getLog().debug("Starting create queue test");
connect();
queueConnection.start();
drainQueue();
final CountDown counter1 = new CountDown(3);
QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) context.lookup(TEST_QUEUE);
QueueReceiver receiver = session.createReceiver(queue);
receiver.setMessageListener(new MessageListener()
{
public void onMessage(Message msg)
{
Logger log = Logger.getLogger(getClass().getName());
log.debug("ML");
try
{
if (msg instanceof TextMessage)
{
log.debug(((TextMessage) msg).getText());
counter1.release();
}
}
catch (Exception e)
{
}
}
});
QueueSender sender = session.createSender(queue);
TextMessage message = session.createTextMessage();
message.setText("Normal message");
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
//sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
message.setText("Persistent message");
sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
//sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
message.setText("High Priority Persistent message");
sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
//sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
// Wait for the msgs to be received
counter1.acquire();
log.debug("MessageListener1 received the TMs sent");
final CountDown counter2 = new CountDown(2);
receiver.setMessageListener(new MessageListener()
{
public void onMessage(Message msg)
{
Logger log = Logger.getLogger(getClass().getName());
log.debug("ML 2");
try
{
if (msg instanceof TextMessage)
{
log.debug(((TextMessage) msg).getText());
counter2.release();
}
}
catch (Exception e)
{
}
}
});
message.setText("Persistent message");
sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
//sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
message.setText("High Priority Persistent message");
sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
//sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
// Wait for the msgs to be received
counter2.acquire();
log.debug("MessageListener2 received the TMs sent");
receiver.setMessageListener(null);
message.setText("Persistent message");