Skip to content

Publish/Subscribe

Overview

The Pub-Sub Object sample demonstrates publish-subscribe messaging with an object payload

In publish-subscribe, messages from a sender can be received by any number of parties who have a matching subscription

In this sample, the “Sender” program acts as a publisher. 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 “ContactSender” which is the Id of the party that is being used. “ContactSender” can be found in this sample’s Neuron solution in the Messaging tab under “Publishers”. Similarly, the “Receiver” programs acts as a publisher and the “Receiver2” program acts as a publisher and subscriber. Their party Ids, which are “ContactReceiver” and “ContactReceiver2”, can be found in the App.config files for their respective programs.

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..

This sample is located in the samples hierarchy at Samples\Patterns\PubSub\PubSubObject.

Running the Sample

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the Pub/Sub 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 all three projects.
  2. Build the solution.

Run Instructions

  1. Use Visual Studio to start up all projects.
  2. Once all programs have connected to Neuron ESB, press Enter on the sender to initiate communication.
The Sender program
Figure 1: The Sender program before sending the message
  1. As the sample runs, the sender’s messages are received by multiple receivers with matching subscriptions.
The Receiver program
Figure 2: The Receiver program after receiving the message. Receiver2 should look similar.
Was this article helpful?
Dislike 0
Previous: Itinerary
Next: Request/Reply