Search in sources :

Example 21 with QueueReceiver

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

the class PullingIfsaProviderListener method getRawMessage.

/**
 * Retrieves messages to be processed by the server, implementing an IFSA-service, but does no processing on it.
 */
@Override
public Object getRawMessage(Map threadContext) throws ListenerException {
    Object result = null;
    QueueSession session = null;
    QueueReceiver receiver = null;
    threadContext.remove(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY);
    try {
        session = getSession(threadContext);
        try {
            receiver = getReceiver(threadContext, session);
            result = receiver.receive(getTimeOut());
            while (result == null && canGoOn() && !JtaUtil.inTransaction()) {
                result = receiver.receive(getTimeOut());
            }
        } catch (Exception e) {
            throw new ListenerException(getLogPrefix(), e);
        } finally {
            releaseReceiver(receiver);
        }
    } finally {
        if (sessionNeedsToBeSavedForAfterProcessMessage(result)) {
            threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
        } else {
            releaseSession(session);
        }
    }
    if (result instanceof IFSAPoisonMessage) {
        IFSAHeader header = ((IFSAPoisonMessage) result).getIFSAHeader();
        String source;
        try {
            source = header.getIFSA_Source();
        } catch (Exception e) {
            source = "unknown due to exeption:" + e.getMessage();
        }
        String msg = getLogPrefix() + "received IFSAPoisonMessage " + "source [" + source + "]" + "content [" + ToStringBuilder.reflectionToString((IFSAPoisonMessage) result) + "]";
        log.warn(msg);
    }
    try {
        if ((result instanceof IFSATextMessage || result instanceof IFSAPoisonMessage) && JtaUtil.inTransaction()) {
            threadContext.put(THREAD_CONTEXT_ORIGINAL_RAW_MESSAGE_KEY, result);
            result = new MessageWrapper(result, this);
        }
    } catch (Exception e) {
        throw new ListenerException("cannot wrap non serialzable message in wrapper", e);
    }
    return result;
}
Also used : IFSAHeader(com.ing.ifsa.IFSAHeader) ListenerException(nl.nn.adapterframework.core.ListenerException) QueueReceiver(javax.jms.QueueReceiver) INamedObject(nl.nn.adapterframework.core.INamedObject) MessageWrapper(nl.nn.adapterframework.receivers.MessageWrapper) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) QueueSession(javax.jms.QueueSession) IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) JMSException(javax.jms.JMSException) IFSAPoisonMessage(com.ing.ifsa.IFSAPoisonMessage) IFSATextMessage(com.ing.ifsa.IFSATextMessage)

Example 22 with QueueReceiver

use of javax.jms.QueueReceiver 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();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueReceiver(javax.jms.QueueReceiver) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 23 with QueueReceiver

use of javax.jms.QueueReceiver in project activemq-artemis by apache.

the class QueueReceiverTest method testCreateReceiverWithMessageSelector.

/**
 * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
 */
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
    QueueConnection qc = null;
    try {
        qc = createQueueConnection();
        QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");
        qc.start();
        TextMessage m = qs.createTextMessage();
        m.setText("one");
        m.setBooleanProperty("targetMessage", false);
        QueueSender qsender = qs.createSender(queue1);
        qsender.send(m);
        m.setText("two");
        m.setBooleanProperty("targetMessage", true);
        qsender.send(m);
        TextMessage rm = (TextMessage) qreceiver.receive(1000);
        ProxyAssertSupport.assertEquals("two", rm.getText());
    } finally {
        if (qc != null) {
            qc.close();
        }
        Thread.sleep(2000);
        removeAllMessages(queue1.getQueueName(), true);
        checkEmpty(queue1);
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueReceiver(javax.jms.QueueReceiver) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 24 with QueueReceiver

use of javax.jms.QueueReceiver in project activemq-artemis by apache.

the class ActiveMQRASession method createReceiver.

/**
 * Create a queue receiver
 *
 * @param queue The queue
 * @return The queue receiver
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueReceiver createReceiver(final Queue queue) throws JMSException {
    lock();
    try {
        QueueSession session = getQueueSessionInternal();
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue);
        }
        QueueReceiver result = session.createReceiver(queue);
        result = new ActiveMQRAQueueReceiver(result, this);
        if (ActiveMQRASession.trace) {
            ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result);
        }
        addConsumer(result);
        return result;
    } finally {
        unlock();
    }
}
Also used : QueueReceiver(javax.jms.QueueReceiver) XAQueueSession(javax.jms.XAQueueSession) QueueSession(javax.jms.QueueSession)

Example 25 with QueueReceiver

use of javax.jms.QueueReceiver in project activemq-artemis by apache.

the class SimpleOpenWireTest method testTempQueueDelete.

@Test
public void testTempQueueDelete() throws Exception {
    connection.start();
    QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = queueSession.createTemporaryQueue();
    ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
    try {
        QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender queueSender = newQueueSession.createSender(tempQueue);
        Message msg = queueSession.createMessage();
        queueSender.send(msg);
        try {
            QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
            fail("should have gotten exception but got consumer: " + consumer);
        } catch (JMSException ex) {
        // correct
        }
        connection.close();
        try {
            Message newMsg = newQueueSession.createMessage();
            queueSender.send(newMsg);
        } catch (JMSException e) {
        // ok
        }
    } finally {
        newConn.close();
    }
}
Also used : MapMessage(javax.jms.MapMessage) StreamMessage(javax.jms.StreamMessage) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) QueueSession(javax.jms.QueueSession) 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