Search in sources :

Example 66 with MessageConsumer

use of javax.jms.MessageConsumer in project vcell by virtualcell.

the class VCMessagingServiceActiveMQ method createConsumer.

@Override
public MessageConsumer createConsumer(Session jmsSession, VCDestination vcDestination, VCMessageSelector vcSelector, int prefetchLimit) throws JMSException {
    Destination jmsDestination;
    MessageConsumer jmsMessageConsumer;
    if (vcDestination instanceof VCellQueue) {
        jmsDestination = jmsSession.createQueue(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    } else {
        jmsDestination = jmsSession.createTopic(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    }
    if (vcSelector == null) {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination);
    } else {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination, vcSelector.getSelectionString());
    }
    return jmsMessageConsumer;
}
Also used : VCDestination(cbit.vcell.message.VCDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) VCellQueue(cbit.vcell.message.VCellQueue)

Example 67 with MessageConsumer

use of javax.jms.MessageConsumer in project vcell by virtualcell.

the class QueueWatcher method start.

public void start() throws JMSException {
    ActiveMQTopic[] tpcs = AdvisorySupport.getAllDestinationAdvisoryTopics(queue);
    for (ActiveMQTopic tp : tpcs) {
        writer.println("watching " + tp.getTopicName());
        Destination ds = session.createTopic(tp.getPhysicalName());
        MessageConsumer c = session.createConsumer(ds);
        c.setMessageListener(new AdvListener(tp.getTopicName()));
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic)

Example 68 with MessageConsumer

use of javax.jms.MessageConsumer in project vcell by virtualcell.

the class VCMessagingServiceEmbedded method createConsumer.

@Override
public MessageConsumer createConsumer(Session jmsSession, VCDestination vcDestination, VCMessageSelector vcSelector, int prefetchLimit) throws JMSException, VCMessagingException {
    if (!initialized) {
        initialized = true;
        init();
    }
    Destination jmsDestination;
    MessageConsumer jmsMessageConsumer;
    if (vcDestination instanceof VCellQueue) {
        jmsDestination = jmsSession.createQueue(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    } else {
        jmsDestination = jmsSession.createTopic(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    }
    if (vcSelector == null) {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination);
    } else {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination, vcSelector.getSelectionString());
    }
    return jmsMessageConsumer;
}
Also used : VCDestination(cbit.vcell.message.VCDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) VCellQueue(cbit.vcell.message.VCellQueue)

Example 69 with MessageConsumer

use of javax.jms.MessageConsumer in project tomee by apache.

the class JmsTest method createListener.

private Destination createListener(final Connection connection) throws JMSException {
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the request Queue
    final Destination requestQueue = session.createQueue(REQUEST_QUEUE_NAME);
    final MessageConsumer consumer = session.createConsumer(requestQueue);
    consumer.setMessageListener(new MessageListener() {

        @Override
        @SuppressWarnings("unchecked")
        public void onMessage(final Message message) {
            // if we got a dummy (non ObjectMessage) return
            if (!(message instanceof ObjectMessage))
                return;
            MessageProducer producer = null;
            try {
                // process request
                final ObjectMessage requestMessage = (ObjectMessage) message;
                final Map<String, Object[]> request = (Map<String, Object[]>) requestMessage.getObject();
                final Object[] args = request.get("args");
                final String returnValue = "test-" + args[0];
                // create response map
                final Map<String, Object> response = new TreeMap<String, Object>();
                response.put("return", returnValue);
                // create response message
                final ObjectMessage responseMessage = session.createObjectMessage();
                responseMessage.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
                responseMessage.setObject((Serializable) response);
                // send response message
                producer = session.createProducer(requestMessage.getJMSReplyTo());
                producer.send(responseMessage);
            } catch (final Throwable e) {
                e.printStackTrace();
            } finally {
                MdbUtil.close(producer);
            }
        }
    });
    return requestQueue;
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Serializable(java.io.Serializable) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) Map(java.util.Map) TreeMap(java.util.TreeMap) Session(javax.jms.Session)

Example 70 with MessageConsumer

use of javax.jms.MessageConsumer in project tomee by apache.

the class MdbTest method createSender.

private void createSender() throws JMSException {
    Connection connection = null;
    Session session = null;
    MessageProducer producer = null;
    MessageConsumer consumer = null;
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        // create request
        final Map<String, Object> request = new TreeMap<String, Object>();
        request.put("args", new Object[] { "cheese" });
        // create a new temp response queue
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final Destination responseQueue = session.createTemporaryQueue();
        // Create a request messages
        final ObjectMessage requestMessage = session.createObjectMessage();
        requestMessage.setJMSReplyTo(responseQueue);
        requestMessage.setObject((Serializable) request);
        // Send the request message
        producer = session.createProducer(session.createQueue(REQUEST_QUEUE_NAME));
        producer.send(requestMessage);
        // wait for the response message
        consumer = session.createConsumer(responseQueue);
        final Message message = consumer.receive(30000);
        // verify message
        assertNotNull("Did not get a response message", message);
        assertTrue("Response message is not an ObjectMessage", message instanceof ObjectMessage);
        final ObjectMessage responseMessage = (ObjectMessage) message;
        final Serializable object = responseMessage.getObject();
        assertNotNull("Response ObjectMessage contains a null object");
        assertTrue("Response ObjectMessage does not contain an instance of Map", object instanceof Map);
        final Map<String, String> response = (Map<String, String>) object;
        // process results
        final String returnValue = (String) response.get("return");
        assertEquals("test-cheese", returnValue);
    } finally {
        MdbUtil.close(consumer);
        MdbUtil.close(producer);
        MdbUtil.close(session);
        MdbUtil.close(connection);
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Serializable(java.io.Serializable) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TreeMap(java.util.TreeMap) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) TreeMap(java.util.TreeMap) Map(java.util.Map) Session(javax.jms.Session)

Aggregations

MessageConsumer (javax.jms.MessageConsumer)107 Session (javax.jms.Session)64 Message (javax.jms.Message)50 MessageProducer (javax.jms.MessageProducer)49 Connection (javax.jms.Connection)47 TextMessage (javax.jms.TextMessage)45 Test (org.junit.Test)45 Destination (javax.jms.Destination)24 JMSException (javax.jms.JMSException)23 ConnectionFactory (javax.jms.ConnectionFactory)15 TemporaryQueue (javax.jms.TemporaryQueue)9 Queue (javax.jms.Queue)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 ObjectMessage (javax.jms.ObjectMessage)7 MessageListener (javax.jms.MessageListener)6 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 HornetQMixIn (org.switchyard.component.test.mixins.hornetq.HornetQMixIn)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3