List of usage examples for javax.jms Session close
void close() throws JMSException;
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 av a 2 s . com 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:com.linagora.obm.sync.TestQueueManager.java
@Test public void testDurableSubscription() throws Exception { String testText = "test text"; String clientId = "c1"; Connection connection = queueManager.createConnection(); connection.setClientID(clientId);/*from ww w.j a v a 2 s . c om*/ connection.start(); Session consumerSession = queueManager.createSession(connection); MessageConsumer consumer = queueManager.createDurableConsumerOnTopic(consumerSession, TOPIC, clientId); consumerSession.close(); connection.close(); writeMessageOnTopic(testText, TOPIC, queueManager); Connection connection2 = createManagedConnection(); connection2.setClientID(clientId); connection2.start(); consumerSession = queueManager.createSession(connection2); consumer = queueManager.createDurableConsumerOnTopic(consumerSession, TOPIC, clientId); TextMessage messageReceived = (TextMessage) consumer.receive(TIMEOUT); Assert.assertEquals(testText, messageReceived.getText()); }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.jms.HermesJmsRequestTransport.java
protected void closeSessionAndConnection(Connection connection, Session session) throws JMSException { if (session != null) session.close(); if (connection != null) connection.close();//w w w . j a va2s . c om }
From source file:com.fusesource.forge.jmstest.benchmark.command.transport.JMSCommandTransport.java
public void sendCommand(BenchmarkCommand command) { log.debug("Sending command message: " + command.toString()); if (getConnection() != null) { try {/*from ww w. j a va 2 s. c om*/ Session session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); Destination dest = getJmsDestinationProvider().getDestination(session, getDestinationName()); MessageProducer producer = session.createProducer(dest); producer.send(session.createObjectMessage((Serializable) command)); session.close(); } catch (Exception je) { log().error("Could not send Command " + command.toString() + ".", je); } } else { log.warn("Command not sent as JMS connection is not established."); } }
From source file:com.linagora.obm.sync.TestQueueManager.java
@Test public void testClosedSession() throws Exception { String testText = "test text"; Connection connection = createManagedConnection(); connection.start();/*from w w w . j a v a 2 s . c o m*/ Session consumerSession = queueManager.createSession(connection); MessageConsumer consumer = queueManager.createConsumerOnTopic(consumerSession, TOPIC); writeMessageOnTopic(testText, TOPIC, queueManager); TextMessage messageReceived1 = (TextMessage) consumer.receive(TIMEOUT); consumerSession.close(); writeMessageOnTopic(testText, TOPIC, queueManager); consumerSession = createManagedSession(connection); consumer = queueManager.createConsumerOnTopic(consumerSession, TOPIC); TextMessage messageReceived2 = (TextMessage) consumer.receive(TIMEOUT); Assert.assertEquals(testText, messageReceived1.getText()); Assert.assertNull(messageReceived2); }
From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java
public void testJmsCorrelationIdToAdaptrisMessageMetadata_NoValue() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); JmsConnection conn = broker.getJmsConnection(); try {//from ww w . java 2 s .co m broker.start(); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); TextMessage jmsMsg = session.createTextMessage(); MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY); mcs.processCorrelationId(jmsMsg, adpMsg); assertFalse(adpMsg.containsKey(CORRELATIONID_KEY)); session.close(); } finally { stop(conn); broker.destroy(); } }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
private Boolean submitToBackend(final String messageId) { Connection connection;//from w ww . j a v a 2s.co m MessageProducer producer; 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: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 . ja v a2s. c o m*/ // 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:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java
public void testAdaptrisMessageMetadataToJmsCorrelationId_EmptyValue() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); JmsConnection conn = broker.getJmsConnection(); try {//ww w . j a v a 2s .com broker.start(); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); adpMsg.addMetadata(CORRELATIONID_KEY, ""); TextMessage jmsMsg = session.createTextMessage(); MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY); mcs.processCorrelationId(adpMsg, jmsMsg); assertTrue(StringUtils.isEmpty(jmsMsg.getJMSCorrelationID())); session.close(); } finally { stop(conn); broker.destroy(); } }
From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java
public void testJmsCorrelationIdToAdaptrisMessageMetadata_NoMetadataKey() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); JmsConnection conn = broker.getJmsConnection(); try {//www . ja v a 2s .c o m broker.start(); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); TextMessage jmsMsg = session.createTextMessage(); jmsMsg.setJMSCorrelationID(TEXT2); MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(); mcs.processCorrelationId(jmsMsg, adpMsg); assertNotSame(jmsMsg.getJMSCorrelationID(), adpMsg.getMetadataValue(CORRELATIONID_KEY)); session.close(); } finally { stop(conn); broker.destroy(); } }