Skip to content

Request/Reply

Overview

The Request-Reply Object sample demonstrates request-reply messaging with an object payload.

In request-reply, the message sender expects a reply back. A request message from a sender can be replied to by any matching subscriber. The sender blocks waiting for a response after sending the request.

In this sample, the “Sender” program acts as a publisher and subscriber. The party’s Id is contained in the program’s App.config file in the XPath “configuration/appSettings” as an “add” element. The key for the “add” element is “esbClientId” and the value is “ContactRequester” which is the Id of the party that is being used. “ContactRequester” can be found in this sample’s Neuron solution in the Messaging tab under “Publishers” and “Subscribers”. Similarly, the “Receiver” program acts as a publisher and subscriber and its party Id, which is “ContactResponder”, can be found in the App.config file for the “Receiver” program.

As an alternative to using the App.config file to set the Publisher or Subscriber Id, they can be set programmatically when creating the Publisher or Subscriber object by passing in a string containing the Id of the Publisher or Subscriber to the constructor. Also, the party sending the request does not need receive rights to the topic being used to receive the response nor does the responding party need send rights to send back the reply. So, in other words, the “ContactRequester” party could be only a publisher and the “ContactResponder” party could be only a subscriber if the user chooses to do so.

This sample is located in the samples hierarchy at Samples\Patterns\Request Reply.

Running the Sample

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the Request Reply sample.

Setup Instructions

Before running this sample, follow these instructions:

  1. In the Visual Studio project that opens, add a reference to Neuron.Esb.dll in both the Receiver and Server projects.
  2. Configure the solution for multiple startup projects, setting both projects to Start.
  3. Build the solution.

Run Instructions

  1. In Visual Studio, press F5 to start both projects.
  2. Once all programs have connected to the ESB, press <ENTER> on the sender to initiate communication.
The sender program
Figure 1: The sender program waiting to send the request
  1. As the sample runs, the sender’s requests are responded to, and the sender displays the response information.
The sender program
Figure 2: The sender program after receiving the contact from the receiver program
The receiver program after sending the contact
Figure 3: The receiver program after sending the contact
Was this article helpful?
Dislike 0
Previous: Publish/Subscribe
Next: Itinerary