List of usage examples for javax.jms Connection close
void close() throws JMSException;
From source file:org.apache.activemq.store.kahadb.SubscriptionRecoveryTest.java
private void createInactiveDurableSub(Topic topic) throws Exception { Connection connection = cf.createConnection(); connection.setClientID("Inactive"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createDurableSubscriber(topic, "Inactive"); consumer.close();//ww w . j a va2s . c om connection.close(); }
From source file:org.wildfly.camel.test.jms.TransactedJMSIntegrationTest.java
@Test public void testJMSTransactionToDLQ() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addComponent("jms", jmsComponent); camelctx.addRoutes(configureJmsRoutes()); camelctx.start();//from w w w . j a v a 2 s . com PollingConsumer consumer = camelctx.getEndpoint("direct:dlq").createPollingConsumer(); consumer.start(); // Send a message to queue camel-jms-queue-one Connection connection = connectionFactory.createConnection(); sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Bob"); // The JMS transaction should have been rolled back and the message sent to the DLQ String result = consumer.receive().getIn().getBody(String.class); Assert.assertNotNull(result); Assert.assertEquals("Hello Bob", result); connection.close(); camelctx.stop(); }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
private void consumeTestMessage() throws Exception { final Connection connection = factory.createConnection(); connection.start();/* w ww.j ava2s .c om*/ try { final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageConsumer consumer = session.createConsumer(session.createQueue(QNAME)); final Message message = consumer.receive(1000); LOG.info(ObjectUtils.toString(message, "<no message>")); Assert.assertEquals(uniqueId, ((TextMessage) message).getText()); } finally { connection.stop(); connection.close(); } }
From source file:org.wildfly.camel.test.jms.TransactedJMSIntegrationTest.java
@Test public void testJMSTransaction() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addComponent("jms", jmsComponent); camelctx.addRoutes(configureJmsRoutes()); camelctx.start();/*from w w w.ja va2 s . co m*/ PollingConsumer consumer = camelctx.getEndpoint("direct:success").createPollingConsumer(); consumer.start(); // Send a message to queue camel-jms-queue-one Connection connection = connectionFactory.createConnection(); sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Kermit"); // The JMS transaction should have been committed and the message payload sent to the direct:success endpoint String result = consumer.receive().getIn().getBody(String.class); Assert.assertNotNull(result); Assert.assertEquals("Hello Kermit", result); connection.close(); camelctx.stop(); }
From source file:com.mirth.connect.connectors.jms.JmsDispatcher.java
private void closeJmsConnection(String connectionKey) throws Exception { JmsConnection jmsConnection = jmsConnections.get(connectionKey); if (jmsConnection != null) { try {/* ww w.ja v a 2 s. c o m*/ Exception firstException = null; Connection connection = jmsConnection.getConnection(); if (connection != null) { try { connection.close(); } catch (JMSException e) { firstException = e; logger.debug("Failed to close the JMS connection", e); } } Context initialContext = jmsConnection.getInitialContext(); if (initialContext != null) { try { initialContext.close(); } catch (NamingException e) { if (firstException == null) { firstException = e; } logger.debug("Failed to close the initial context", e); } initialContext = null; } if (firstException != null) { throw firstException; } } finally { jmsConnections.remove(connectionKey); } } }
From source file:org.dhatim.routing.jms.JMSRouter.java
protected void close(final Connection connection) { if (connection != null) { try {// w w w. j av a2s .c om connection.close(); } catch (JMSException e) { final String errorMsg = "JMSException while trying to close connection"; logger.debug(errorMsg, e); } } }
From source file:nl.nn.adapterframework.jms.MessagingSource.java
private void releaseConnection(Connection connection) { if (connection != null && connectionsArePooled()) { try {//w w w . j a va 2s . c om // do not log, as this may happen very often // if (log.isDebugEnabled()) log.debug(getLogPrefix()+"closing Connection, openConnectionCount will become ["+(openConnectionCount.getValue()-1)+"]"); connection.close(); openConnectionCount.decrease(); } catch (JMSException e) { log.error(getLogPrefix() + "Exception closing Connection", e); } } }
From source file:org.apache.synapse.message.store.impl.jms.JmsStore.java
/** * Closes the given JMS Connection.//from w ww.j av a2 s. co m * * @param connection The JMS Connection to be closed. * @return true if the connection was successfully closed. false otherwise. */ public boolean closeConnection(Connection connection) { try { connection.close(); if (logger.isDebugEnabled()) { logger.debug(nameString() + " closed connection to JMS broker."); } } catch (JMSException e) { return false; } return true; }
From source file:org.apache.flume.source.jms.TestIntegrationActiveMQ.java
private void putQueue(List<String> events) throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL); Connection connection = factory.createConnection(); connection.start();/*from w ww. j av a2s. com*/ Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(DESTINATION_NAME); MessageProducer producer = session.createProducer(destination); for (String event : events) { TextMessage message = session.createTextMessage(); message.setText(event); producer.send(message); } session.commit(); session.close(); connection.close(); }
From source file:org.apache.flume.source.jms.TestIntegrationActiveMQ.java
private void putTopic(List<String> events) throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL); Connection connection = factory.createConnection(); connection.start();//ww w . j a v a 2 s. co m Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(DESTINATION_NAME); MessageProducer producer = session.createProducer(destination); for (String event : events) { TextMessage message = session.createTextMessage(); message.setText(event); producer.send(message); } session.commit(); session.close(); connection.close(); }