List of usage examples for javax.jms QueueConnection close
void close() throws JMSException;
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 .ja v a 2s .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.siddhi.extension.output.transport.jms.util.QueueConsumer.java
public void run() { // create queue connection QueueConnection queueConnection = null; try {// w ww . j av a 2s . 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); } }
From source file:pl.psnc.synat.wrdz.zu.certificate.CertificateChecker.java
/** * Notifies the system monitor that the given user has a certificate that's beyond the expiration threshold. * /*from ww w . jav a2 s . c om*/ * @param username * name of the user with the (nearly) expired certificate */ private void notifyExpirationCheckFail(String username) { QueueConnection connection = null; try { connection = queueConnectionFactory.createQueueConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage message = session.createTextMessage(); message.setText(username); session.createProducer(certificateQueue).send(message); } catch (JMSException e) { logger.error("Sending message to the JMS queue failed", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { logger.error("Error while closing a connection.", e); } } } }