use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.
the class TemporaryQueueTest method testClosingSessionDoesNotDeleteQueue.
@Test
public void testClosingSessionDoesNotDeleteQueue() throws Exception {
final Connection connection = getConnection();
try {
final Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final TemporaryQueue queue = session1.createTemporaryQueue();
assertNotNull("Temporary queue cannot be null", queue);
MessageProducer producer = session1.createProducer(queue);
String messageText = "Hello World!";
producer.send(session1.createTextMessage(messageText));
session1.close();
connection.start();
MessageConsumer consumer = session2.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 wildfly by wildfly.
the class MDBWithVaultedPropertiesTestCase method sendAndReceiveMessage.
@Test
public void sendAndReceiveMessage() {
try (JMSContext context = factory.createContext()) {
TemporaryQueue replyTo = context.createTemporaryQueue();
String text = UUID.randomUUID().toString();
context.createProducer().setJMSReplyTo(replyTo).send(queue, text);
JMSConsumer consumer = context.createConsumer(replyTo);
String reply = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
assertEquals(text, reply);
}
}
use of javax.jms.TemporaryQueue in project eap-additional-testsuite by jboss-set.
the class VaultedInjectedJMSContextTestCase method sendMessage.
@Test
public void sendMessage() throws JMSException {
String text = UUID.randomUUID().toString();
try (JMSContext context = factory.createContext()) {
TemporaryQueue tempQueue = context.createTemporaryQueue();
producerBean.sendToDestination(tempQueue, text);
JMSConsumer consumer = context.createConsumer(tempQueue);
String reply = consumer.receiveBody(String.class, adjust(2000));
assertEquals(text, reply);
}
}
use of javax.jms.TemporaryQueue in project eap-additional-testsuite by jboss-set.
the class InjectedJMSContextTestCase method sendWith_REQUIRED_transaction.
private void sendWith_REQUIRED_transaction(boolean rollback) throws JMSException {
String text = UUID.randomUUID().toString();
try (JMSContext context = factory.createContext()) {
TemporaryQueue tempQueue = context.createTemporaryQueue();
producerBean.sendToDestination(tempQueue, text, rollback);
assertMessageIsReceived(tempQueue, context, text, rollback);
}
}
use of javax.jms.TemporaryQueue in project javaee7-samples by javaee-samples.
the class JmsClient method process.
// <1> we need to send message in the middle of the method, therefore we cannot be transactional
@TransactionAttribute(NOT_SUPPORTED)
public String process(String request) {
TextMessage requestMessage = jms.createTextMessage(request);
TemporaryQueue responseQueue = jms.createTemporaryQueue();
jms.createProducer().setJMSReplyTo(// <2> set the temporary queue as replyToDestination
responseQueue).send(requestQueue, // <3> immediately send the request message
requestMessage);
try (JMSConsumer consumer = jms.createConsumer(responseQueue)) {
// <4> listen on the temporary queue
// <5> wait for a +TextMessage+ to arrive
String response = consumer.receiveBody(String.class, 20000);
if (response == null) {
// <6> +receiveBody+ returns +null+ in case of timeout
throw new IllegalStateException("Message processing timed out");
}
return response;
}
}
Aggregations