Search in sources :

Example 56 with ObjectMessage

use of javax.jms.ObjectMessage in project gocd by gocd.

the class JMSMessageListenerAdapter method runImpl.

protected boolean runImpl() {
    try {
        Message message = consumer.receive();
        if (message == null) {
            LOG.debug("Message consumer was closed.");
            return true;
        }
        ObjectMessage omessage = (ObjectMessage) message;
        daemonThreadStatsCollector.captureStats(thread.getId());
        listener.onMessage((GoMessage) omessage.getObject());
    } catch (JMSException e) {
        LOG.warn("Error receiving message. Message receiving will continue despite this error.", e);
    } catch (Exception e) {
        LOG.error("Exception thrown in message handling by listener {}", listener, e);
    } finally {
        daemonThreadStatsCollector.clearStats(thread.getId());
    }
    return false;
}
Also used : ObjectMessage(javax.jms.ObjectMessage) GoMessage(com.thoughtworks.go.server.messaging.GoMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException)

Example 57 with ObjectMessage

use of javax.jms.ObjectMessage in project apex-malhar by apache.

the class ActiveMQMultiTypeMessageListener method onMessage.

@Override
public void onMessage(Message message) {
    super.onMessage(message);
    if (message instanceof TextMessage) {
        TextMessage txtMsg = (TextMessage) message;
        String msg = null;
        try {
            msg = txtMsg.getText();
            receivedData.put(countMessages, msg);
        } catch (JMSException ex) {
            logger.debug(ex.getLocalizedMessage());
        }
        logger.debug("Received a TextMessage: {}", msg);
    } else if (message instanceof MapMessage) {
        MapMessage mapMsg = (MapMessage) message;
        Map map = new HashMap();
        try {
            Enumeration en = mapMsg.getMapNames();
            while (en.hasMoreElements()) {
                String key = (String) en.nextElement();
                map.put(key, mapMsg.getObject(key));
            }
            receivedData.put(countMessages, map);
        } catch (JMSException ex) {
            logger.debug(ex.getLocalizedMessage());
        }
        logger.debug("Received a MapMessage: {}", map);
    } else if (message instanceof BytesMessage) {
        BytesMessage bytesMsg = (BytesMessage) message;
        try {
            byte[] byteArr = new byte[(int) bytesMsg.getBodyLength()];
            bytesMsg.readBytes(byteArr);
            receivedData.put(countMessages, byteArr);
        } catch (JMSException ex) {
            logger.debug(ex.getLocalizedMessage());
        }
        logger.debug("Received a ByteMessage: {}", bytesMsg);
    } else if (message instanceof ObjectMessage) {
        ObjectMessage objMsg = (ObjectMessage) message;
        Object msg = null;
        try {
            msg = objMsg.getObject();
            receivedData.put(countMessages, msg);
        } catch (JMSException ex) {
            logger.debug(ex.getLocalizedMessage());
        }
        logger.debug("Received an ObjectMessage: {}", msg);
    } else {
        throw new IllegalArgumentException("Unhandled message type " + message.getClass().getName());
    }
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) ObjectMessage(javax.jms.ObjectMessage) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) BytesMessage(javax.jms.BytesMessage) Map(java.util.Map) HashMap(java.util.HashMap) TextMessage(javax.jms.TextMessage)

Example 58 with ObjectMessage

use of javax.jms.ObjectMessage in project ignite by apache.

the class IgniteJmsStreamerTest method testQueueFromExplicitDestination.

/**
 * @throws Exception If failed.
 */
public void testQueueFromExplicitDestination() throws Exception {
    Destination dest = new ActiveMQQueue(QUEUE_NAME);
    // produce messages into the queue
    produceObjectMessages(dest, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestination(dest);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        // start the streamer
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) ObjectMessage(javax.jms.ObjectMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 59 with ObjectMessage

use of javax.jms.ObjectMessage in project ignite by apache.

the class IgniteJmsStreamerTest method testQueueMultipleThreads.

/**
 * @throws Exception If failed.
 */
public void testQueueMultipleThreads() throws Exception {
    Destination dest = new ActiveMQQueue(QUEUE_NAME);
    // produce messages into the queue
    produceObjectMessages(dest, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestination(dest);
        jmsStreamer.setThreads(5);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        // start the streamer
        jmsStreamer.start();
        DestinationStatistics qStats = broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics();
        assertEquals(5, qStats.getConsumers().getCount());
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        // assert that all consumers received messages - given that the prefetch is 1
        for (Subscription subscription : broker.getBroker().getDestinationMap().get(dest).getConsumers()) assertTrue(subscription.getDequeueCounter() > 0);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ObjectMessage(javax.jms.ObjectMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(org.apache.activemq.broker.region.Subscription)

Example 60 with ObjectMessage

use of javax.jms.ObjectMessage in project ignite by apache.

the class IgniteJmsStreamerTest method testTopicFromExplicitDestination.

/**
 * @throws Exception If failed.
 */
public void testTopicFromExplicitDestination() throws JMSException, InterruptedException {
    Destination dest = new ActiveMQTopic(TOPIC_NAME);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestination(dest);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // produce messages
        produceObjectMessages(dest, false);
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ObjectMessage(javax.jms.ObjectMessage) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)71 JMSException (javax.jms.JMSException)29 Message (javax.jms.Message)24 Session (javax.jms.Session)18 Test (org.junit.Test)18 TextMessage (javax.jms.TextMessage)14 Serializable (java.io.Serializable)11 Destination (javax.jms.Destination)11 Map (java.util.Map)10 BytesMessage (javax.jms.BytesMessage)10 MapMessage (javax.jms.MapMessage)9 MessageProducer (javax.jms.MessageProducer)8 MessageConsumer (javax.jms.MessageConsumer)7 TreeMap (java.util.TreeMap)6 MessageCreator (org.springframework.jms.core.MessageCreator)5 DataNode (com.odysseusinc.arachne.portal.model.DataNode)4 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)3 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)3