Search in sources :

Example 1 with ActiveMQTemporaryTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic in project activemq-artemis by apache.

the class AutoCreateJmsDestinationTest method testTemporaryTopic.

@Test
public void testTemporaryTopic() throws Exception {
    Connection connection = cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // javax.jms.Topic topic = ActiveMQJMSClient.createTopic(QUEUE_NAME);
    ActiveMQTemporaryTopic topic = (ActiveMQTemporaryTopic) session.createTemporaryTopic();
    MessageConsumer consumer = session.createConsumer(topic);
    MessageProducer producer = session.createProducer(topic);
    producer.send(session.createTextMessage("msg"));
    connection.start();
    assertNotNull(consumer.receive(500));
    SimpleString topicAddress = topic.getSimpleAddress();
    consumer.close();
    assertNotNull(server.locateQueue(topicAddress));
    IntegrationTestLogger.LOGGER.info("Topic name: " + topicAddress);
    topic.delete();
    connection.close();
    // assertNotNull(server.getManagementService().getResource("jms.topic.test"));
    assertNull(server.locateQueue(topicAddress));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQTemporaryTopic(org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with ActiveMQTemporaryTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic in project activemq-artemis by apache.

the class CloseDestroyedConnectionTest method testClosingTemporaryTopicDeletesQueue.

@Test
public void testClosingTemporaryTopicDeletesQueue() throws JMSException, ActiveMQException {
    conn = cf.createConnection();
    Assert.assertEquals(1, server.getRemotingService().getConnections().size());
    session1 = (ActiveMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQTemporaryTopic topic = (ActiveMQTemporaryTopic) session1.createTemporaryTopic();
    String address = topic.getAddress();
    session1.close();
    conn.close();
    conn2 = cf.createConnection();
    session2 = (ActiveMQSession) conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ClientSession cs = session2.getCoreSession();
    try {
        cs.createConsumer(address);
        fail("the address from the TemporaryTopic still exists!");
    } catch (ActiveMQException e) {
        assertEquals("expecting 'queue does not exist'", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, e.getType());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQTemporaryTopic(org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic) Test(org.junit.Test)

Aggregations

ActiveMQTemporaryTopic (org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic)2 Test (org.junit.Test)2 Connection (javax.jms.Connection)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1