Using Queue Requestors

The QueueRequestor class provides a simple synchronous request/reply mechanism that a client can use to publish a message to a queue destination and wait for a reply to that message.

To create a Queue Requestor, call javax.jms.QueueRequestor(QueueSession session, Queue queue) and pass in a non‑transacted Session and a queue destination. The Queue Requestor automatically creates a temporary queue that is used for the duration of the Session.

Once a Queue Requestor is created, call the QueueRequestor.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 queue created by the Queue Requestor. (This temporary queue 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 QueueRequestor.close() is called, both the Queue Requestor and the Session that it belongs to are closed.

Related Sample

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