Using Topic Requestors

The TopicRequestor class provides a simple synchronous request/reply mechanism that a client can use to publish a message to a specific topic and wait for a reply to that message.

To create a Topic Requestor, call javax.jms.TopicRequestor() and pass in a non‑transacted Session and a topic destination. The Topic Requestor automatically creates a temporary topic that is used for the duration of the Session.

Once a Topic Requestor is created, call the TopicRequestor.request(Message message) method and pass in the message that you want to request reply to. A reply from a receiving application to the request is directed to the temporary topic created by the Topic Requestor. (This temporary topic acts as the JMSReplyTo destination.) The client that receives the request can use the Message.getJMSReplyTo() method to get the destination that the reply should be sent to.

The first reply is returned to the requesting client; any subsequent replies are discarded. Note that the request waits until a reply is received – no timeout can be set for the request. This is problematic if a reply is slow to return or never arrives.

When TopicRequestor.close() is called, both the Topic Requestor and the Session that it belongs to are closed.

Related Sample

For an example of how to publish use the TopicRequestor class to send messages to temporary topics and request direct replies to those messages, refer to the SolJMSRRGuaranteedRequester and SolJMSRRGuaranteedReplier samples.