use of javax.jms.Message 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.Message in project wildfly by wildfly.
the class ReplyUtil method reply.
public static void reply(ConnectionFactory factory, Message message) {
Connection connection = null;
try {
connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Destination destination = message.getJMSReplyTo();
// ignore messages that need no reply
if (destination == null)
return;
final MessageProducer replyProducer = session.createProducer(destination);
final Message replyMsg = session.createMessage();
replyMsg.setJMSCorrelationID(message.getJMSMessageID());
replyProducer.send(replyMsg);
replyProducer.close();
} catch (JMSException e) {
throw new RuntimeException(e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
}
}
}
}
use of javax.jms.Message in project wildfly by wildfly.
the class MessageDestinationTestCase method testMEssageDestinationResolution.
/**
* Test a deployment descriptor based MDB
* @throws Exception
*/
@Test
public void testMEssageDestinationResolution() throws Exception {
this.messagingMdb.sendTextMessage("Say hello to " + MessagingEjb.class.getName());
final Message reply = this.messagingMdb.receiveMessage(5000);
Assert.assertNotNull("Reply message was null on reply queue", reply);
}
use of javax.jms.Message in project wildfly by wildfly.
the class MessagingEjb method reply.
public void reply(final Message message) throws JMSException {
final Destination destination = message.getJMSReplyTo();
// ignore messages that need no reply
if (destination == null) {
return;
}
final Message replyMsg = session.createTextMessage("replying to message: " + message.toString());
replyMsg.setJMSCorrelationID(message.getJMSMessageID());
this.sendMessage(replyMsg, destination, null);
}
use of javax.jms.Message in project wildfly by wildfly.
the class SetMessageDrivenContextInvocationTestCase method testSetMessageDrivenContext.
/**
* Test that the {@link javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext)}
* was invoked
*
* @throws Exception
*/
@Test
public void testSetMessageDrivenContext() throws Exception {
this.jmsUtil.sendTextMessage("hello world", this.queue, this.replyQueue);
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
final TextMessage textMessage = (TextMessage) reply;
Assert.assertEquals("setMessageDrivenContext method was *not* invoked on MDB", SimpleMDB.SUCCESS_REPLY, textMessage.getText());
}
Aggregations