use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class ScopedInjectedJMSContextTestCase method requestScoped.
/**
* Test that a request-scoped JMSContext is properly cleaned up after the transaction completion.
*/
@Test
public void requestScoped() throws Exception {
String text = UUID.randomUUID().toString();
try (JMSContext context = factory.createContext()) {
TemporaryQueue tempQueue = context.createTemporaryQueue();
// send a request/reply message to ensure that the MDB as received the message
// and set its consumer field
context.createProducer().setJMSReplyTo(tempQueue).setDeliveryMode(NON_PERSISTENT).send(queueForRequestScope, text);
JMSConsumer consumer = context.createConsumer(tempQueue);
String reply = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
assertNotNull(reply);
JMSConsumer consumerInMDB = RequestScopedMDB.consumer;
assertNotNull(consumerInMDB);
try {
consumerInMDB.receiveBody(String.class);
fail("the EJB must throw an exception as its injected JMSContext must be closed after the MDB handled the message");
} catch (Exception e) {
}
}
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class InjectedJMSContextTestCase method sendAndReceiveWithContext.
@Test
public void sendAndReceiveWithContext() throws JMSException {
String text = UUID.randomUUID().toString();
try (JMSContext context = factory.createContext()) {
TemporaryQueue tempQueue = context.createTemporaryQueue();
context.createProducer().send(tempQueue, text);
assertMessageIsReceived(tempQueue, context, text, false);
}
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class MDBTestCase method doDeliveryActive.
private void doDeliveryActive(Destination destination, String mdbName) throws Exception {
// ReplyingMDB has been deployed with deliveryActive set to false
assertMDBDeliveryIsActive(mdbName, false);
Connection connection = null;
try {
connection = cf.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
// send a message to the MDB
MessageProducer producer = session.createProducer(destination);
Message message = session.createMessage();
message.setJMSReplyTo(replyQueue);
producer.send(message);
// the MDB did not reply to the message because its delivery is not active
MessageConsumer consumer = session.createConsumer(replyQueue);
Message reply = consumer.receive(TIMEOUT);
assertNull(reply);
executeMDBOperation(mdbName, "start-delivery");
assertMDBDeliveryIsActive(mdbName, true);
// WFLY-4470 check duplicate message when start delivery twice. Last assertNull(reply) should still be valid
executeMDBOperation(mdbName, "start-delivery");
// the message was delivered to the MDB which replied
reply = consumer.receive(TIMEOUT);
assertNotNull(reply);
assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
executeMDBOperation(mdbName, "stop-delivery");
assertMDBDeliveryIsActive(mdbName, false);
// send again a message to the MDB
message = session.createMessage();
message.setJMSReplyTo(replyQueue);
producer.send(message);
// the MDB did not reply to the message because its delivery is not active
reply = consumer.receive(TIMEOUT);
assertNull(reply);
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class ContainerManagedTransactionNotSupportedTestCase method doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException.
private void doSetRollbackOnlyInContainerManagedTransactionNotSupportedMDBThrowsIllegalStateException(Destination destination) throws Exception {
try (JMSContext context = cf.createContext()) {
TemporaryQueue replyTo = context.createTemporaryQueue();
String text = UUID.randomUUID().toString();
TextMessage message = context.createTextMessage(text);
message.setJMSReplyTo(replyTo);
context.createProducer().send(destination, message);
Message reply = context.createConsumer(replyTo).receive(adjust(5000));
assertNotNull(reply);
assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
assertTrue("messageDrivenContext.setRollbackOnly() did not throw the expected IllegalStateException", reply.getBooleanProperty(EXCEPTION_PROP_NAME));
}
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class JMSHelper method assertSendAndReceiveTextMessage.
public static void assertSendAndReceiveTextMessage(ConnectionFactory cf, Destination destination, String text) throws JMSException {
try (JMSContext context = cf.createContext(AUTO_ACKNOWLEDGE)) {
TemporaryQueue replyTo = context.createTemporaryQueue();
context.createProducer().setJMSReplyTo(replyTo).send(destination, text);
String replyText = context.createConsumer(replyTo).receiveBody(String.class, TimeoutUtil.adjust(5000));
assertEquals(text, replyText);
}
}
Aggregations