List of usage examples for javax.jms Connection close
void close() throws JMSException;
From source file:org.apache.falcon.oozie.workflow.FalconPostProcessingTest.java
private void consumer(String brokerUrl, String topic, boolean checkUserMessage) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); Connection connection = connectionFactory.createConnection(); connection.start();/*from w w w .j a v a 2s . co m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(topic); MessageConsumer consumer = session.createConsumer(destination); latch.countDown(); // Verify user message if (checkUserMessage) { verifyMesssage(consumer); } // Verify falcon message verifyMesssage(consumer); connection.close(); }
From source file:org.apache.activemq.leveldb.test.ReplicatedLevelDBBrokerTest.java
protected Thread startFailoverClient(String name, final Client client) throws IOException, URISyntaxException { String url = "failover://(tcp://localhost:" + port + ")?maxReconnectDelay=500&nested.wireFormat.maxInactivityDuration=1000"; final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url); Thread rc = new Thread(name) { @Override/*ww w .j a v a2 s. c o m*/ public void run() { Connection connection = null; try { connection = factory.createConnection(); client.execute(connection); } catch (Throwable e) { e.printStackTrace(); } finally { try { connection.close(); } catch (JMSException e) { } } } }; rc.start(); return rc; }
From source file:org.aludratest.service.jms.impl.JmsActionImpl.java
@Override public void unsubscribeTopic(@TechnicalArgument String subscriptionName) throws JMSException { if (StringUtils.isEmpty(clientId)) { throw new IllegalArgumentException("Client-Id must be provided to unsubscribe"); }/* ww w . ja v a 2 s . c o m*/ LOGGER.debug("Unsubscribing from subscription " + subscriptionName); Connection c = getDynamicConnection(subscriptionName); c.stop(); TopicSubscriber subscriber = this.durableConsumers.get(subscriptionName); if (subscriber != null) { subscriber.close(); c.createSession(false, Session.AUTO_ACKNOWLEDGE).unsubscribe(subscriptionName); this.durableConsumers.remove(subscriptionName); } c.close(); this.dynamicConnections.remove(c); }
From source file:org.apache.activemq.store.kahadb.SubscriptionRecoveryTest.java
private int consumeFromInactiveDurableSub(Topic topic) throws Exception { Connection connection = cf.createConnection(); connection.setClientID("Inactive"); connection.start();/*from w w w . j a va2 s. c om*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createDurableSubscriber(topic, "Inactive"); int count = 0; while (consumer.receive(10000) != null) { count++; } consumer.close(); connection.close(); return count; }
From source file:nl.nn.adapterframework.jms.JmsMessagingSourceFactory.java
public String getConnectionFactoryInfo(ConnectionFactory connectionFactory) { if (IbisContext.getApplicationServerType().equals("TIBCOAMX")) { // Workaround to prevent the following exception: // [org.apache.geronimo.connector.outbound.MCFConnectionInterceptor] - Error occurred creating ManagedConnection for org.apache.geronimo.connector.outbound.ConnectionInfo@####### // javax.resource.ResourceException: JMSJCA-E084: Failed to create session: The JNDI name is null return null; }// w w w . j a v a2 s .c om String info = null; Connection connection = null; try { connection = connectionFactory.createConnection(); ConnectionMetaData metaData = connection.getMetaData(); info = "jms provider name [" + metaData.getJMSProviderName() + "] jms provider version [" + metaData.getProviderVersion() + "] jms version [" + metaData.getJMSVersion() + "]"; } catch (JMSException e) { log.warn("Exception determining connection factory info", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e1) { log.warn("Exception closing connection for metadata", e1); } } } return info; }
From source file:org.apache.activemq.bugs.AMQ6133PersistJMSRedeliveryTest.java
private void consumerAndRollback(int iteration) throws Exception { Connection connection = createConnection(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(QUEUE_NAME); MessageConsumer consumer = session.createConsumer(queue); long msgCount = getProxyToQueue(queue.getQueueName()).getQueueSize(); for (int i = 0; i < msgCount; ++i) { Message message = consumer.receive(50000); assertNotNull(message);//from w ww. j ava 2 s . c om if (iteration > 0) { assertTrue(message.getJMSRedelivered()); } } connection.close(); }
From source file:com.datatorrent.lib.io.jms.JMSTestBase.java
public void produceMsg(String text) throws Exception { // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); // Create a Connection Connection connection = connectionFactory.createConnection(); connection.start();//from w ww. j av a2 s. com // Create a Session Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = session.createQueue("TEST.FOO"); // Create a MessageProducer from the Session to the Topic or Queue MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); // Create a messages TextMessage message = session.createTextMessage(text); producer.send(message); // Clean up session.close(); connection.close(); }
From source file:org.apache.activemq.store.kahadb.SubscriptionRecoveryTest.java
private void tryConsumeExpectNone(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"); connection.start();/*w w w . jav a2 s . c o m*/ if (consumer.receive(TimeUnit.SECONDS.toMillis(10)) != null) { fail("Should be no messages for this durable."); } consumer.close(); connection.close(); }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
private Boolean submitToBackend(final String messageId) { Connection connection; MessageProducer producer;//w w w. j ava 2 s .co m try { connection = this.cf.createConnection(); final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.receivingQueue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); final MapMessage resMessage = session.createMapMessage(); this.downloadMessage(messageId, resMessage); producer.send(resMessage); producer.close(); session.close(); connection.close(); } catch (JMSException | ValidationException e) { BackendJMSImpl.LOG.error("", e); return false; } return true; }
From source file:org.apache.activemq.leveldb.test.ReplicatedLevelDBBrokerTest.java
private void sendMessage(BrokerService brokerService, String body) throws Exception { TransportConnector connector = brokerService.getTransportConnectors().get(0); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connector.getConnectUri()); Connection connection = factory.createConnection(); try {// w w w.j av a 2 s. co m connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(session.createQueue("FOO")); producer.send(session.createTextMessage(body)); } finally { connection.close(); } }