Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMS ReplyTo - How does it work?

Tags:

jakarta-ee

jms

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.

like image 731
Synesso Avatar asked Jan 13 '12 05:01

Synesso


People also ask

How does JMS connection work?

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.

How does JMS listener work?

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.

What is JMS request reply?

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.

What is JMSReplyTo?

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.


1 Answers

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();
like image 81
Aravind Yarram Avatar answered Oct 12 '22 09:10

Aravind Yarram