The JMS API allows messages to declare a replyTo Destination
instance. (i.e. the superclass of Queue
, Topic
). A service could then send a reply message to the sender using this queue.
Are there any restrictions on what Destination
can be set as a ReplyTo value? That seems unlikely to work, for the service may not even have any network route to the defined Destination
and therefore could not return any message. Does JMS somehow assert the validity (reachability) of a provided Destination
? Or is it simply up to the service to try to respond on the given Destination
and fail if necessary.
Each client connects to a messaging agent that provides facilities for creating, sending, receiving, and reading messages. Messaging enables distributed communication that is loosely coupled. A component sends a message to a destination, and the recipient can retrieve the message from the destination.
The JMS Listener adapter operates in an asynchronous mode. It establishes an asynchronous listener on the queue or topic destination specified by the JNDI name of Destination field. When a qualified message arrives at the destination, the adapter immediately processes the message.
JMS Request Reply is an asynchronous activity that is used to send a request to a JMS destination and wait for a response from the JMS client.
Name. JMSReplyTo — Purpose: Routing. In some cases, a message producer may want the consumers to reply to a message. The JMSReplyTo header indicates which destination, if any, a JMS consumer should reply to. The JMSReplyTo header is set explicitly by the JMS client; its contents will be a javax.
Scenario 1
In this scenario the Destination
is pre-configured and hence proven to work. There is not much value to set this destination as a value for JMSReplyTo
header as the receiver might already know about the existence of this pre-configured destination.
Scenario 2
In this scenario the sender creates a temporary Destination and receiver will know about this only by calling getJMSReplyTo()
method on the received Message
. This kind of establishes a private channel between sender and receiver. Read this nice article on pros and cons of temporary destinations.
Sample code
Queue tempQueue = qSession.createTemporaryQueue();
TextMessage request = qSession.createTextMessage();
request.setJMSReplyTo(tempQueue);
QueueReceiver qReceiver = qSession.createReceiver(tmpQueue);
Message response = qReceiver.receive();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With