use of javax.jms.QueueSession in project wildfly by wildfly.
the class PooledEJBLifecycleTestCase method triggerRequestResponseCycleOnQueue.
// ------------------ HELPER METHODS -------------------
private void triggerRequestResponseCycleOnQueue() throws Exception {
final InitialContext ctx = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
final QueueConnection connection = factory.createQueueConnection();
try {
connection.start();
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final String requestMessage = "test";
final Message message = session.createTextMessage(requestMessage);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) ctx.lookup(Constants.QUEUE_JNDI_NAME);
final MessageProducer producer = session.createProducer(destination);
// create receiver
final QueueReceiver receiver = session.createReceiver(replyDestination);
producer.send(message);
producer.close();
//wait for reply
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
assertNotNull("Did not receive a reply on the reply queue. Perhaps the original (request) message didn't make it to the MDB?", reply);
final String result = ((TextMessage) reply).getText();
assertEquals("Unexpected reply messsage", Constants.REPLY_MESSAGE_PREFIX + requestMessage, result);
} finally {
if (connection != null) {
// just closing the connection will close the session and other related resources (@see javax.jms.Connection)
safeClose(connection);
}
}
}
use of javax.jms.QueueSession in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method receiveMessage.
static String receiveMessage(Queue replyQueue, InitialContext initCtx) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final QueueReceiver receiver = session.createReceiver(replyQueue);
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
// waiting for synchro could be finished before checking
Thread.sleep(TimeoutUtil.adjust(500));
if (reply == null)
return null;
return ((TextMessage) reply).getText();
} finally {
connection.close();
}
}
use of javax.jms.QueueSession in project wildfly by wildfly.
the class JMSMessageDrivenBeanTestCase method testSendMessage.
@Test
public void testSendMessage() throws JMSException, NamingException {
final InitialContext ctx = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
final QueueConnection connection = factory.createQueueConnection();
connection.start();
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final QueueReceiver receiver = session.createReceiver(replyDestination);
final Message message = session.createTextMessage("Test");
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) ctx.lookup("queue/myAwesomeQueue");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
assertNotNull(reply);
final String result = ((TextMessage) reply).getText();
assertEquals("replying Test", result);
} finally {
connection.close();
}
}
use of javax.jms.QueueSession in project wildfly by wildfly.
the class MDBEJBRuntimeNameTestsCase method testMDB.
@Test
@InSequence(1)
public void testMDB() throws Exception {
final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("java:/jms/RemoteConnectionFactory");
final QueueConnection connection = factory.createQueueConnection("guest", "guest");
try {
connection.start();
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final String requestMessage = "test";
final Message message = session.createTextMessage(requestMessage);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) context.lookup(Constants.QUEUE_JNDI_NAME);
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
// wait for a reply
final QueueReceiver receiver = session.createReceiver(replyDestination);
final Message reply = receiver.receive(TimeoutUtil.adjust(1000));
assertNotNull("Did not receive a reply on the reply queue. Perhaps the original (request) message didn't make it to the MDB?", reply);
final String result = ((TextMessage) reply).getText();
assertEquals("Unexpected reply messsage", Constants.REPLY_MESSAGE_PREFIX + requestMessage, result);
} finally {
if (connection != null) {
// just closing the connection will close the session and other related resources (@see javax.jms.Connection)
safeClose(connection);
}
}
}
Aggregations