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();
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
Aggregations