Search in sources :

Example 51 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueuePrefixTest method testEmptyPrefix.

@Test
public void testEmptyPrefix() throws Exception {
    updateGlobalAddressDomains("[]");
    Connection connection = getConnection();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue queue = session.createTemporaryQueue();
        assertTrue(queue.getQueueName() + " does not start with \"TempQueue\".", queue.getQueueName().startsWith("TempQueue"));
    } finally {
        connection.close();
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) Session(javax.jms.Session) Test(org.junit.Test)

Example 52 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method testMessageDeliveryUsingTemporaryQueue.

@Test
public void testMessageDeliveryUsingTemporaryQueue() throws Exception {
    final Connection connection = getConnection();
    try {
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final TemporaryQueue queue = session.createTemporaryQueue();
        assertNotNull("Temporary queue cannot be null", queue);
        final MessageProducer producer = session.createProducer(queue);
        final MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        producer.send(session.createTextMessage("hello"));
        Message message = consumer.receive(getReceiveTimeout());
        assertTrue("TextMessage should be received", message instanceof TextMessage);
        assertEquals("hello", ((TextMessage) message).getText());
    } finally {
        connection.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 53 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method testClosingConsumerDoesNotDeleteQueue.

@Test
public void testClosingConsumerDoesNotDeleteQueue() throws Exception {
    final Connection connection = getConnection();
    try {
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final TemporaryQueue queue = session.createTemporaryQueue();
        assertNotNull("Temporary queue cannot be null", queue);
        MessageProducer producer = session.createProducer(queue);
        String messageText = "Hello World!";
        producer.send(session.createTextMessage(messageText));
        connection.start();
        session.createConsumer(queue).close();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(getReceiveTimeout());
        assertTrue("Received message not a text message", message instanceof TextMessage);
        assertEquals("Incorrect message text", messageText, ((TextMessage) message).getText());
    } finally {
        connection.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 54 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method testPublishFromAnotherConnectionAllowed.

@Test
public void testPublishFromAnotherConnectionAllowed() throws Exception {
    final Connection connection = getConnection();
    try {
        final Connection connection2 = getConnection();
        try {
            final Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final TemporaryQueue queue = session1.createTemporaryQueue();
            assertNotNull("Temporary queue cannot be null", queue);
            MessageProducer producer = session2.createProducer(queue);
            producer.send(session2.createMessage());
            connection.start();
            MessageConsumer consumer = session1.createConsumer(queue);
            Message message = consumer.receive(getReceiveTimeout());
            assertNotNull("Message not received", message);
        } finally {
            connection2.close();
        }
    } finally {
        connection.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) Session(javax.jms.Session) Test(org.junit.Test)

Example 55 with TemporaryQueue

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

the class JmsTempDestinationTest method testTempDestOnlyConsumedByLocalConn.

/**
 * Make sure Temp destination can only be consumed by local connection
 *
 * @throws JMSException
 */
@Test
public void testTempDestOnlyConsumedByLocalConn() throws JMSException {
    connection.start();
    Session tempSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue queue = tempSession.createTemporaryQueue();
    MessageProducer producer = tempSession.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    TextMessage message = tempSession.createTextMessage("First");
    producer.send(message);
    // temp destination should not be consume when using another connection
    Connection otherConnection = factory.createConnection();
    connections.add(otherConnection);
    Session otherSession = otherConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue otherQueue = otherSession.createTemporaryQueue();
    MessageConsumer consumer = otherSession.createConsumer(otherQueue);
    Message msg = consumer.receive(3000);
    Assert.assertNull(msg);
    // destination from another connection
    try {
        consumer = otherSession.createConsumer(queue);
        Assert.fail("Send should fail since temp destination should be used from another connection");
    } catch (InvalidDestinationException e) {
        Assert.assertTrue("failed to throw an exception", true);
    }
    // should be able to consume temp destination from the same connection
    consumer = tempSession.createConsumer(queue);
    msg = consumer.receive(3000);
    Assert.assertNotNull(msg);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

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