use of javax.jms.Destination in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method sendMessage.
static Queue sendMessage(String text, String queueJndi, InitialContext initCtx) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
Queue replyDestination = null;
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Message message = session.createTextMessage(text);
replyDestination = (Queue) initCtx.lookup(TransactionTimeoutQueueSetupTask.REPLY_QUEUE_JNDI_NAME);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) initCtx.lookup(queueJndi);
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
} finally {
connection.close();
}
return replyDestination;
}
use of javax.jms.Destination in project wildfly by wildfly.
the class SimpleTimerMDBTestCase method sendMessage.
//the timer is created when the
public void sendMessage() throws Exception {
final InitialContext ctx = new InitialContext();
final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
final TopicConnection connection = factory.createTopicConnection();
connection.start();
try {
final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
final Message message = session.createTextMessage("Test");
final Destination destination = (Destination) ctx.lookup("topic/myAwesomeTopic");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
} finally {
connection.close();
}
}
use of javax.jms.Destination 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.Destination 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.Destination in project wildfly by wildfly.
the class SimpleMDB method onMessage.
@Override
public void onMessage(Message message) {
logger.trace("Received message: " + message);
try {
final Destination replyTo = message.getJMSReplyTo();
if (replyTo != null) {
logger.trace("Replying to " + replyTo);
try (JMSContext context = factory.createContext()) {
String reply = (messageDrivenContext != null) ? SUCCESS_REPLY : FAILURE_REPLY;
context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
}
}
} catch (JMSException jmse) {
throw new RuntimeException(jmse);
}
}
Aggregations