Request Reply Messaging

The Request-Reply messaging pattern is different from the Publish-Subscribe messaging pattern because each time the subscriber consumes a message it sends a response to the publisher. For more information see Publishing Messages that Request Replies.

This section provides an overview of the basic steps that required to implement a request reply messaging model using Guaranteed messages. Note that client applications must use a mechanism to correlate the request message with the reply message. Using the CorrelationID message property is one possible mechanism to achieve that goal.

  1. Publishing Guaranteed Request Messages
  2. Replying to Guaranteed Request Messages
  3. Receiving Reply Messages
  4. Request Reply Example

If you're doing request/reply messaging with Multi-Node Routing (MNR), you must use the request/reply methods of the Solace APIs to prevent possible race conditions associated with subscription propagation.

Publishing Guaranteed Request Messages

To send a Guaranteed message that requires a corresponding reply from a consuming client, perform the following steps:

  1. Create the message and set the following message properties:
    • a persistent or non-persistent delivery mode
    • a unique ReplyTo destination. This is the destination a consuming client must send the reply to the request message to. This ReplyTo destination can be temporary (that is, a temporary topic or queue), or it can be durable (for example, a durable queue or a topic subscription assigned to a durable queue).
    • a topic or queue destination to publish the request message to (see Destination). (Note: When using JCSMP, the destination is not a message property; instead it is passed in when the send() method is called.)
    • (optional, but recommended) a unique CorrelationID. A correlation ID enables a response to be matched to the request. When used, the implementation of correlation ID matching is the responsibility of the application.

      For information on setting message properties, see Setting Message Properties.

  2. Add the message content. For more information, see Adding Data Payloads.
  3. Send the request message. For more information, see Sending One Message at a Time.

Replying to Guaranteed Request Messages

To send a Guaranteed message as a reply to a received Guaranteed request message, perform the following steps:

  1. Receive the request message.

    To receive the request message, a replying client must use a Guaranteed message flow to bind to the provisioned endpoint that the published message is enqueued to. (For information, see Creating Flows.) The endpoint to bind to could be one of the following:

    • A queue that matches the messages’ queue destination.
    • A queue that is assigned a topic subscription that matches the message’s topic destination.
    • A topic endpoint that is assigned a topic subscription that matches the message’s topic destination.
  2. Get the following properties from the received request message so that they can be used to form the reply:
  3. Create the reply message and set the following message properties:
    • a persistent or non-persistent delivery mode
    • a destination to publish the reply message to. This is the ReplyTo destination (either a topic or queue) that is obtained from the request message. : (When using JCSMP, the destination is not a message property; instead, it is passed in when the send() method is called.)
    • (optional) a CorrelationID that matches the Correlation ID (if provided) in the request message.

      For information on setting message properties, see Setting Message Properties.

  4. Add the message content. For more information, see Adding Data Payloads.
  5. Send the reply message. For more information, Sending One Message at a Time.

Receiving Reply Messages

The process for receiving a reply message that is sent in response to a request is essentially the same process that is used to receive other Guaranteed messages:

After a replying client has received the request message, processed it, and returned a reply message in response, a receiving client can consume the reply message through a flow that is bound to the provisioned endpoint that the reply message will be enqueued to. (For information, see Creating Flows).

Although it is not a requirement, the receiving client can be the same client that originally sent the request that the reply was sent in response to.

Request Reply Example

It is important to note that in this example that topic subscriptions are first added to the provisioned durable endpoints so that the replying client can receive the request and the requesting client can receive the corresponding response.

Process for Issuing Requests and Receiving Replies