By
using ‘setJMSReplyTo’ header, you can set the destination where a reply to the
message should be sent. This header field is supplied by a client when a
message is sent.
Ex
Destination
acknowledgeQueue = session.createQueue(ACKNOWLEDGEMENT_QUEUE);
message.setJMSReplyTo(acknowledgeQueue);
JMSProducer.java
package com.sample.producer; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; public class JMSProducer { private static final String JMS_PROVIDER_URL = "tcp://127.0.0.1:5050"; private static final String QUEUE = "DEMO_QUEUE"; private static final String ACKNOWLEDGEMENT_QUEUE = "ACKNOWLEDGEMENT_QUEUE"; public static void main(String[] args) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(JMS_PROVIDER_URL); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Destination destination = session.createQueue(QUEUE); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("Hello, this is my first message."); Destination acknowledgeQueue = session.createQueue(ACKNOWLEDGEMENT_QUEUE); message.setJMSReplyTo(acknowledgeQueue); producer.send(message); connection.close(); } }
No comments:
Post a Comment