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\Pub/Sub.
Running the Sample
Open the Sample
To open this sample, see the topic Using the Neuron Samples and select the Pub/Sub sample.
Before running this sample, follow these instructions:
- In the Visual Studio project that opens, add a reference to Neuron.Esb.dll in all three projects.
- Configure the solution for multiple startup projects, setting all three projects to Start.
- Build the solution.
- In Visual Studio, press F5 to start all three projects.
- Once all programs have connected to Neuron ESB, press Enter on the sender to initiate communication.
- As the sample runs, the sender’s messages are received by multiple receivers with matching subscriptions.