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;
}
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());
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations