InitialContext ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
QueueConnection queConn = null;
QueueSession session = null;
QueueSender sender = null;
QueueReceiver receiver = null;
try
{
queConn = factory.createQueueConnection();
queConn.start();
Queue queueA = (Queue) ctx.lookup("queue/A");
Queue queueB = (Queue) ctx.lookup("queue/B");
session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
sender = session.createSender(queueA);
receiver = session.createReceiver(queueB);
while (receiver.receive(1000) != null)
{
// Empty the queue
}
TextMessage message = session.createTextMessage();
message.setText("testMDBTimer");
message.setIntProperty("UNIQUE_ID", 123456789);
message.setJMSReplyTo(queueB);
sender.send(message);
// Get the initial onMessage ack
Message reply = receiver.receive(30000);
log.info("onMessage reply: " + reply);
assertTrue("onMessage reply != null", reply != null);
if (log.isDebugEnabled())
{
log.debug("Properties");
Enumeration e = reply.getPropertyNames();
while (e.hasMoreElements())
{
log.debug(e.nextElement());
}
}
int id = reply.getIntProperty("UNIQUE_ID");
log.debug("id=" + id);
assertTrue("onMessage reply.id = 123456789", id == 123456789);
// Get the initial timer reply
reply = receiver.receive(30000);
log.info("ejbTimeout reply: " + reply);
assertTrue("ejbTimeout reply != null", reply != null);
if (log.isDebugEnabled())
{
log.debug("Properties");
Enumeration e = reply.getPropertyNames();
while (e.hasMoreElements())
{
log.debug(e.nextElement());
}
}
id = reply.getIntProperty("UNIQUE_ID");
log.debug("id=" + id);
assertTrue("onMessage reply.id = 123456789", id == 123456789);
}
finally
{
if (receiver != null)
{
try
{
receiver.close();
} catch (JMSException ignore)
{
//
}
}
if (sender != null)
{
try
{
sender.close();
} catch (JMSException ignore)
{
//
}
}