Search in sources :

Example 21 with QueueConnection

use of javax.jms.QueueConnection 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);
        }
    }
}
Also used : Destination(javax.jms.Destination) QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) QueueReceiver(javax.jms.QueueReceiver) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

QueueConnection (javax.jms.QueueConnection)21 QueueSession (javax.jms.QueueSession)15 TextMessage (javax.jms.TextMessage)12 QueueConnectionFactory (javax.jms.QueueConnectionFactory)10 Test (org.junit.Test)9 Message (javax.jms.Message)8 MessageProducer (javax.jms.MessageProducer)7 Queue (javax.jms.Queue)7 Connection (javax.jms.Connection)5 Destination (javax.jms.Destination)5 QueueReceiver (javax.jms.QueueReceiver)5 QueueSender (javax.jms.QueueSender)5 TopicConnection (javax.jms.TopicConnection)5 InitialContext (javax.naming.InitialContext)4 ObjectMessage (javax.jms.ObjectMessage)3 ConnectionFactory (javax.jms.ConnectionFactory)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2 TopicConnectionFactory (javax.jms.TopicConnectionFactory)2 IOException (java.io.IOException)1