Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) context.lookup(TEST_QUEUE);
MessageConsumer receiver = session.createConsumer(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)
{
}
}
});
MessageProducer sender = session.createProducer(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, 9, 0);
//sender.send(queue, message, DeliveryMode.PERSISTENT, 9, 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");