public void delete() throws JMSException { if (session != null) { /** * The status of the session used to create the temporary destination is uncertain, but the JMS spec states * that the lifetime of the temporary destination is tied to the connection so even if the originating * session is closed the temporary destination should still be deleted. Therefore, just create a new one * and close it after the temporary destination is deleted. This is necessary because the Core API is * predicated on having a Core ClientSession which is encapsulated by the JMS session implementation. */ try (ActiveMQSession sessionToUse = (ActiveMQSession) session.getConnection().createSession()) { if (isQueue()) { sessionToUse.deleteTemporaryQueue(this); } else { sessionToUse.deleteTemporaryTopic(this); } } } }
public void delete() throws JMSException { if (session != null) { /** * The status of the session used to create the temporary destination is uncertain, but the JMS spec states * that the lifetime of the temporary destination is tied to the connection so even if the originating * session is closed the temporary destination should still be deleted. Therefore, just create a new one * and close it after the temporary destination is deleted. This is necessary because the Core API is * predicated on having a Core ClientSession which is encapsulated by the JMS session implementation. */ try (ActiveMQSession sessionToUse = (ActiveMQSession) session.getConnection().createSession()) { if (isQueue()) { sessionToUse.deleteTemporaryQueue(this); } else { sessionToUse.deleteTemporaryTopic(this); } } } }
public void delete() throws JMSException { if (session != null) { /** * The status of the session used to create the temporary destination is uncertain, but the JMS spec states * that the lifetime of the temporary destination is tied to the connection so even if the originating * session is closed the temporary destination should still be deleted. Therefore, just create a new one * and close it after the temporary destination is deleted. This is necessary because the Core API is * predicated on having a Core ClientSession which is encapsulated by the JMS session implementation. */ try (ActiveMQSession sessionToUse = (ActiveMQSession) session.getConnection().createSession()) { if (isQueue()) { sessionToUse.deleteTemporaryQueue(this); } else { sessionToUse.deleteTemporaryTopic(this); } } } }
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(queueName);
@Test public void testTemporaryQueueLeak() throws Exception { ActiveMQConnection conn = null; try { conn = (ActiveMQConnection) createConnection(); Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue tempQueue = producerSession.createTemporaryQueue(); MessageProducer producer = producerSession.createProducer(tempQueue); MessageConsumer consumer = consumerSession.createConsumer(tempQueue); conn.start(); final String messageText = "This is a message"; javax.jms.Message m = producerSession.createTextMessage(messageText); producer.send(m); TextMessage m2 = (TextMessage) consumer.receive(2000); assertNotNull(m2); assertEquals(messageText, m2.getText()); consumer.close(); tempQueue.delete(); assertFalse(conn.containsKnownDestination(SimpleString.toSimpleString(tempQueue.getQueueName()))); assertFalse(conn.containsTemporaryQueue(SimpleString.toSimpleString(tempQueue.getQueueName()))); } finally { if (conn != null) { conn.close(); } } } @Test
Session sessLive = connLive.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
session = connection.createSession(true, Session.SESSION_TRANSACTED); queue = session.createQueue(JMS_SOURCE_QUEUE); targetQueue = session.createQueue(JMS_TARGET_QUEUE);