List of usage examples for javax.jms Message toString
public String toString()
From source file:org.wso2.carbon.integration.test.client.JMSConsumerClient.java
public void run() { // create topic connection TopicConnection topicConnection = null; try {/*w w w . j ava2s . c o m*/ topicConnection = topicConnectionFactory.createTopicConnection(); topicConnection.start(); } catch (JMSException e) { log.error("Can not create topic connection." + e.getMessage(), e); return; } Session session = null; try { session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(topicName); MessageConsumer consumer = session.createConsumer(destination); log.info("Listening for messages"); while (active) { Message message = consumer.receive(1000); if (message != null) { messageCount++; if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } preservedEventList.add(map); log.info("Received Map Message : \n" + map + "\n"); } else if (message instanceof TextMessage) { String textMessage = ((TextMessage) message).getText(); preservedEventList.add(textMessage); log.info("Received Text Message : \n" + textMessage + "\n"); } else { preservedEventList.add(message.toString()); log.info("Received message : \n" + message.toString() + "\n"); } } } log.info("Finished listening for messages."); session.close(); topicConnection.stop(); topicConnection.close(); } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } }
From source file:org.wso2.carbon.sample.consumer.QueueConsumer.java
public void run() { // create queue connection QueueConnection queueConnection = null; try {//from w w w .j av a 2 s . c om queueConnection = queueConnectionFactory.createQueueConnection(); queueConnection.start(); } catch (JMSException e) { log.error("Can not create queue connection." + e.getMessage(), e); return; } Session session = null; try { session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(queueName); MessageConsumer consumer = session.createConsumer(destination); log.info("Listening for messages"); while (active) { Message message = consumer.receive(1000); if (message != null) { if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } log.info("Received Map Message : " + map); } else if (message instanceof TextMessage) { log.info("Received Text Message : " + ((TextMessage) message).getText()); } else { log.info("Received message : " + message.toString()); } } } log.info("Finished listening for messages."); session.close(); queueConnection.stop(); queueConnection.close(); } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } }
From source file:org.wso2.carbon.sample.consumer.TopicConsumer.java
public void run() { // create topic connection TopicConnection topicConnection = null; try {/*from w w w . j a v a2 s . c om*/ topicConnection = topicConnectionFactory.createTopicConnection(); topicConnection.start(); } catch (JMSException e) { log.error("Can not create topic connection." + e.getMessage(), e); return; } Session session = null; try { session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(topicName); MessageConsumer consumer = session.createConsumer(destination); log.info("Listening for messages"); while (active) { Message message = consumer.receive(1000); if (message != null) { if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } log.info("Received Map Message : " + map); } else if (message instanceof TextMessage) { log.info("Received Text Message : " + ((TextMessage) message).getText()); } else { log.info("Received message : " + message.toString()); } } } log.info("Finished listening for messages."); session.close(); topicConnection.stop(); topicConnection.close(); } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } }
From source file:org.wso2.extension.siddhi.io.jms.sink.util.QueueConsumer.java
public void run() { // create queue connection QueueConnection queueConnection = null; try {//from w w w . j a v a2 s. co m queueConnection = queueConnectionFactory.createQueueConnection(); queueConnection.start(); } catch (JMSException e) { log.error("Can not create queue connection." + e.getMessage(), e); return; } Session session; try { session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(queueName); MessageConsumer consumer = session.createConsumer(destination); log.info("Listening for messages at " + queueName); while (active) { Message message = consumer.receive(1000); if (message != null) { resultContainer.eventReceived(message); if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } log.info("Received Map Message: " + map); } else if (message instanceof TextMessage) { log.info("Received Text Message: " + ((TextMessage) message).getText()); } else { log.info("Received message: " + message.toString()); } } } log.info("Finished listening for messages."); session.close(); queueConnection.stop(); queueConnection.close(); } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } }
From source file:org.wso2.extension.siddhi.io.jms.sink.util.ResultContainer.java
public void eventReceived(Message message) { eventCount++; results.add(message.toString()); latch.countDown(); }
From source file:org.wso2.extension.siddhi.io.jms.sink.util.TopicConsumer.java
public void run() { // create topic connection TopicConnection topicConnection = null; try {/*from w ww. j av a2 s .c om*/ topicConnection = topicConnectionFactory.createTopicConnection(); topicConnection.start(); } catch (JMSException e) { log.error("Can not create topic connection." + e.getMessage(), e); return; } Session session = null; try { session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(topicName); MessageConsumer consumer = session.createConsumer(destination); log.info("Listening for messages"); while (active) { Message message = consumer.receive(1000); if (message != null) { resultContainer.eventReceived(message); if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } log.info("Received Map Message : " + map); } else if (message instanceof TextMessage) { log.info("Received Text Message : " + ((TextMessage) message).getText()); } else { log.info("Received message : " + message.toString()); } } } log.info("Finished listening for messages."); session.close(); topicConnection.stop(); topicConnection.close(); } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } }
From source file:org.wso2.siddhi.extension.output.transport.jms.util.QueueConsumer.java
public void run() { // create queue connection QueueConnection queueConnection = null; try {//from w ww.ja va 2 s. c o m queueConnection = queueConnectionFactory.createQueueConnection(); queueConnection.start(); } catch (JMSException e) { log.error("Can not create queue connection." + e.getMessage(), e); return; } Session session; try { session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(queueName); MessageConsumer consumer = session.createConsumer(destination); log.info("Listening for messages at " + queueName); while (active) { Message message = consumer.receive(1000); if (message != null) { if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } log.info("Received Map Message: " + map); } else if (message instanceof TextMessage) { log.info("Received Text Message: " + ((TextMessage) message).getText()); } else { log.info("Received message: " + message.toString()); } } } log.info("Finished listening for messages."); session.close(); queueConnection.stop(); queueConnection.close(); } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } }