use of javax.jms.JMSContext in project wildfly by wildfly.
the class ExportImportJournalTestCase method receiveMessage.
protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, String expectedText) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
if (expectReceivedMessage) {
assertNotNull(text);
assertEquals(expectedText, text);
} else {
assertNull("should not have received any message", text);
}
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class PrintDataTestCase method sendMessage.
protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest", JMSContext.AUTO_ACKNOWLEDGE)) {
TextMessage message = context.createTextMessage(text);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
context.createProducer().send(destination, message);
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class PrintDataTestCase method receiveMessage.
protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, String expectedText) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, TimeoutUtil.adjust(5000));
if (expectReceivedMessage) {
assertNotNull(text);
assertEquals(expectedText, text);
} else {
assertNull("should not have received any message", text);
}
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class LifecycleCounterMDB method onMessage.
@Override
public void onMessage(Message message) {
try {
log.trace(this + " received message " + message);
final Destination replyTo = message.getJMSReplyTo();
// ignore messages that need no reply
if (replyTo == null) {
log.trace(this + " noticed that no reply-to replyTo has been set. Just returning");
return;
}
try (JMSContext context = factory.createContext()) {
String reply = Constants.REPLY_MESSAGE_PREFIX + ((TextMessage) message).getText();
context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
}
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
use of javax.jms.JMSContext in project wildfly by wildfly.
the class ClusteredMessagingTestCase method receiveMessage.
protected static void receiveMessage(Context ctx, Destination destination, String expectedText) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
assertNotNull(destination);
try (JMSContext context = cf.createContext(JMS_USERNAME, JMS_PASSWORD)) {
JMSConsumer consumer = context.createConsumer(destination);
receiveMessage(consumer, expectedText);
}
}
Aggregations