Search in sources :

Example 61 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class TemporaryDestinationTest method testTemporaryQueueDeleted.

@Test
public void testTemporaryQueueDeleted() throws Exception {
    Connection conn = null;
    try {
        conn = createConnection();
        Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Make sure temporary queue cannot be used after it has been deleted
        TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
        MessageProducer producer = producerSession.createProducer(tempQueue);
        MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
        conn.start();
        final String messageText = "This is a message";
        Message m = producerSession.createTextMessage(messageText);
        producer.send(m);
        TextMessage m2 = (TextMessage) consumer.receive(2000);
        ProxyAssertSupport.assertNotNull(m2);
        ProxyAssertSupport.assertEquals(messageText, m2.getText());
        consumer.close();
        tempQueue.delete();
        conn.close();
        conn = createConnection("guest", "guest");
        try {
            producer.send(m);
            ProxyAssertSupport.fail();
        } catch (JMSException e) {
        }
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 62 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class TemporaryDestinationTest method testTemporaryQueueDeleteWithConsumer.

@Test
public void testTemporaryQueueDeleteWithConsumer() throws Exception {
    Connection conn = null;
    try {
        conn = createConnection();
        Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
        MessageConsumer consumer = consumerSession.createConsumer(tempQueue);
        try {
            tempQueue.delete();
            ProxyAssertSupport.fail("Should throw JMSException");
        } catch (JMSException e) {
        // Should fail - you can't delete a temp queue if it has active consumers
        }
        consumer.close();
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 63 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class TemporaryDestinationTest method testTemporaryQueueBasic.

@Test
public void testTemporaryQueueBasic() throws Exception {
    Connection conn = null;
    try {
        conn = 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";
        Message m = producerSession.createTextMessage(messageText);
        producer.send(m);
        TextMessage m2 = (TextMessage) consumer.receive(2000);
        ProxyAssertSupport.assertNotNull(m2);
        ProxyAssertSupport.assertEquals(messageText, m2.getText());
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 64 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class MemoryAllocationTest method releaseDestination.

protected void releaseDestination(Destination dest) throws JMSException {
    if (dest instanceof TemporaryTopic) {
        TemporaryTopic tt = (TemporaryTopic) dest;
        tt.delete();
    } else if (dest instanceof TemporaryQueue) {
        TemporaryQueue tq = (TemporaryQueue) dest;
        tq.delete();
    }
}
Also used : TemporaryQueue(javax.jms.TemporaryQueue) TemporaryTopic(javax.jms.TemporaryTopic)

Example 65 with TemporaryQueue

use of javax.jms.TemporaryQueue in project activemq-artemis by apache.

the class ThreeBrokerTempQueueNetworkTest method testTempQueueCleanup.

/**
 * BrokerA -> BrokerB -> BrokerC
 */
public void testTempQueueCleanup() throws Exception {
    // Setup broker networks
    bridgeBrokers("BrokerA", "BrokerB", false, 2);
    bridgeBrokers("BrokerB", "BrokerC", false, 2);
    startAllBrokers();
    BrokerItem brokerItem = brokers.get("BrokerC");
    Connection conn = brokerItem.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQ = sess.createTemporaryQueue();
    Thread.sleep(5000);
    for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext(); ) {
        BrokerItem bi = i.next();
        assertEquals("No queues on broker " + bi.broker.getBrokerName(), 1, bi.broker.getAdminView().getTemporaryQueues().length);
    }
    tempQ.delete();
    Thread.sleep(2000);
    for (Iterator<BrokerItem> i = brokers.values().iterator(); i.hasNext(); ) {
        BrokerItem bi = i.next();
        assertEquals("Temp queue left behind on broker " + bi.broker.getBrokerName(), 0, bi.broker.getAdminView().getTemporaryQueues().length);
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) Session(javax.jms.Session)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5