Search in sources :

Example 31 with QueueReceiver

use of javax.jms.QueueReceiver in project iaf by ibissource.

the class IfsaMessagingSource method getReplyReceiver.

/**
 * Gets the queueReceiver, by utilizing the <code>getInputQueue()</code> method.<br/>
 * For serverside getQueueReceiver() the creating of the QueueReceiver is done
 * without the <code>selector</code> information, as this is not allowed
 * by IFSA.<br/>
 * For a clientconnection, the receiver is done with the <code>getClientReplyQueue</code>
 */
public QueueReceiver getReplyReceiver(QueueSession session, Message sentMessage) throws IfsaException {
    QueueReceiver queueReceiver;
    String correlationId;
    Queue replyQueue;
    try {
        // IFSA uses the messageId as correlationId
        correlationId = sentMessage.getJMSMessageID();
        replyQueue = (Queue) sentMessage.getJMSReplyTo();
    } catch (JMSException e) {
        throw new IfsaException(e);
    }
    try {
        if (hasDynamicReplyQueue() && !useSingleDynamicReplyQueue()) {
            queueReceiver = session.createReceiver(replyQueue);
            log.debug("created receiver on individual dynamic reply queue");
        } else {
            String selector = "JMSCorrelationID='" + correlationId + "'";
            queueReceiver = session.createReceiver(replyQueue, selector);
            log.debug("created receiver on static or shared-dynamic reply queue - selector [" + selector + "]");
        }
    } catch (JMSException e) {
        throw new IfsaException(e);
    }
    return queueReceiver;
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) QueueReceiver(javax.jms.QueueReceiver) JMSException(javax.jms.JMSException) Queue(javax.jms.Queue) IFSAQueue(com.ing.ifsa.IFSAQueue)

Example 32 with QueueReceiver

use of javax.jms.QueueReceiver in project iaf by ibissource.

the class PullingIfsaProviderListener method closeThread.

@Override
public void closeThread(Map threadContext) throws ListenerException {
    if (!isSessionsArePooled()) {
        QueueReceiver receiver = (QueueReceiver) threadContext.remove(THREAD_CONTEXT_RECEIVER_KEY);
        releaseReceiver(receiver);
        QueueSession session = (QueueSession) threadContext.remove(THREAD_CONTEXT_SESSION_KEY);
        closeSession(session);
    }
}
Also used : QueueReceiver(javax.jms.QueueReceiver) QueueSession(javax.jms.QueueSession)

Example 33 with QueueReceiver

use of javax.jms.QueueReceiver 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();
    }
}
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) InitialContext(javax.naming.InitialContext) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 34 with QueueReceiver

use of javax.jms.QueueReceiver 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);
        }
    }
}
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) InitialContext(javax.naming.InitialContext) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 35 with QueueReceiver

use of javax.jms.QueueReceiver in project wildfly by wildfly.

the class MDBRoleTestCase method testIsMDBinRole.

@Test
public void testIsMDBinRole() throws NamingException, JMSException {
    final InitialContext ctx = new InitialContext();
    final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
    final QueueConnection connection = factory.createQueueConnection();
    connection.start();
    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("Let's test it!");
    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(SimpleSLSB.SUCCESS, result);
    connection.close();
}
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) InitialContext(javax.naming.InitialContext) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

QueueReceiver (javax.jms.QueueReceiver)56 QueueSession (javax.jms.QueueSession)47 Queue (javax.jms.Queue)40 TextMessage (javax.jms.TextMessage)28 Message (javax.jms.Message)25 QueueSender (javax.jms.QueueSender)25 Test (org.junit.jupiter.api.Test)17 QueueConnection (javax.jms.QueueConnection)13 Serializable (java.io.Serializable)11 JMSException (javax.jms.JMSException)10 Test (org.junit.Test)10 QueueConnectionFactory (javax.jms.QueueConnectionFactory)6 BytesMessage (javax.jms.BytesMessage)5 InitialContext (javax.naming.InitialContext)5 Destination (javax.jms.Destination)4 MessageProducer (javax.jms.MessageProducer)4 NamingException (javax.naming.NamingException)4 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)3 Enumeration (java.util.Enumeration)3 HashMap (java.util.HashMap)3