List of usage examples for javax.jms Connection close
void close() throws JMSException;
From source file:org.wso2.carbon.event.output.adaptor.jms.JMSEventAdaptorType.java
@Override public void testConnection(OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) { try {//from www . jav a 2 s. c om Hashtable<String, String> adaptorProperties = new Hashtable<String, String>(); adaptorProperties.putAll(outputEventAdaptorConfiguration.getOutputProperties()); JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory(adaptorProperties, outputEventAdaptorConfiguration.getName()); Connection connection = jmsConnectionFactory.getConnection(); connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.close(); jmsConnectionFactory.stop(); } catch (Exception e) { throw new OutputEventAdaptorEventProcessingException(e); } }
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueSendReceiveTest.java
@Test public void testSend() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(activeMQTestQueueA); producer.setDeliveryMode(DeliveryMode.PERSISTENT); TextMessage message = session.createTextMessage("test text"); producer.send(message);// w ww.jav a2s.c om connection.close(); }
From source file:com.linagora.obm.sync.TestQueueManager.java
private void shutdownQueueManager() { for (Session s : sessions) { try {//from w ww . j a va2s.c om s.close(); } catch (JMSException e) { logger.error(e.getMessage(), e); } } for (Connection c : connections) { try { c.stop(); } catch (JMSException e) { logger.error(e.getMessage(), e); } try { c.close(); } catch (JMSException e) { logger.error(e.getMessage(), e); } } try { queueManager.stop(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:org.aludratest.service.jms.impl.JmsActionImpl.java
public void close() { LOGGER.info("Closing JmsServcie for clientId " + this.clientId); for (TopicSubscriber subscriber : this.durableConsumers.values()) { try {//from w w w .j a v a2 s . c o m subscriber.close(); } catch (JMSException e) { LOGGER.debug("Failed to close subscriber: ", e); } } for (Map.Entry<String, Connection> entry : this.dynamicConnections.entrySet()) { try { Connection dynC = entry.getValue(); dynC.stop(); dynC.close(); } catch (JMSException e) { LOGGER.debug("Failed to close dynamic connection [ " + entry.getKey() + " ] : ", e); } } if (session != null) { try { session.close(); } catch (JMSException e) { LOGGER.debug("Failed to close jms session : ", e); } } if (connection != null) { try { connection.stop(); connection.close(); } catch (JMSException e) { LOGGER.debug("Failed to close jms connection for client-id [ " + this.clientId + " ] : ", e); } } }
From source file:unic.mentoring.jms.ctrl.MessageCtrl.java
protected void sendMessage(String message, String topicName) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); Connection connection = connectionFactory.createConnection(); connection.start();/*from w ww . ja va 2 s .c o m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); TextMessage jmsMessage = session.createTextMessage(); jmsMessage.setText(message); producer.send(jmsMessage); connection.close(); }
From source file:org.eclipse.smila.connectivity.queue.worker.internal.task.impl.Send.java
/** * close connection if not null, catching and logging possible exceptions. * //from w w w . j a v a 2 s .c om * @param connection * a JMS conection */ private void closeQuietly(final Connection connection) { if (connection != null) { try { connection.stop(); } catch (final Throwable e) { _log.error("Unable to stop connection", e); } try { connection.close(); } catch (final Throwable e) { _log.error("Unable to close connection", e); } } }
From source file:com.aol.advertising.qiao.emitter.AMQEmitter.java
@ManagedOperation public void resetConnections() { producersStack.clear();/*from ww w .j a v a 2 s . c o m*/ for (Connection conn : connList) { try { conn.close(); } catch (Exception e) { logger.error(e.getMessage()); } } connList.clear(); try { createJmsResources(); this.start(); logger.info(this.getClass().getSimpleName() + " re-started"); } catch (Exception e) { logger.error("failed to create JMS resources - " + e.getClass().getName() + ": " + e.getMessage(), e); } }
From source file:Log4jJMSAppenderExample.java
public Log4jJMSAppenderExample() throws Exception { // create a logTopic topic consumer ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start();//from w w w. j a v a 2 s. c o m MessageConsumer consumer = sess.createConsumer(sess.createTopic("logTopic")); consumer.setMessageListener(this); // log a message Logger log = Logger.getLogger(Log4jJMSAppenderExample.class); log.info("Test log"); // clean up Thread.sleep(1000); consumer.close(); sess.close(); conn.close(); System.exit(1); }
From source file:org.apache.activemq.camel.JmsJdbcXARollbackTest.java
private boolean consumedFrom(String qName) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA"); factory.setWatchTopicAdvisories(false); Connection connection = factory.createConnection(); connection.start();/*www . j a va 2 s .c o m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(new ActiveMQQueue(qName)); Message message = consumer.receive(500); LOG.info("Got from queue:{} {}", qName, message); connection.close(); return message != null; }
From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java
@Test public void testReceive() throws Exception { Connection connection = testConnectionFactory.createConnection(); connection.start();//from w w w. j a va2 s . co m Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(testQueueA); Message rawMessage = consumer.receive(); assertTrue(rawMessage instanceof TextMessage); TextMessage message = (TextMessage) rawMessage; assertEquals("test text", message.getText()); connection.close(); }