Dynamic Routing by Content
- Home
- Neuron ESB
- Development
- Samples and Walkthroughs
- Process Samples
- Dynamic Routing by Content
Overview
This sample demonstrates how you can use a Publish Neuron Process step to route a message to different topics using the Publish step’s TopicSelector Code option. With the TopicSelector Code option, the topic that a Publish process step sends messages on can be dynamically set at runtime based on selector code defined by the user. For example, the selector code can inspect the incoming message and set the outgoing topic based on some property of the message or some content found inside the message body. In this example the selector code will look for the value of a certain Xml node attribute extracted via an XPath expression.
Process Components Demonstrated:
- Publish
- Cancel
Solution
The Dynamic Topic Routing – Content process depicted in Figure 1 has a Publish process step named “contact selector pub” and a Cancel process step named “end message”. These steps are contained within the Try and Finally execution blocks of an Exception process step. Inside the Catch execution block, a Process Execute step calls the Exception Handling process to process any exceptions that might arise.
The “contact selector pub” Publish process step is using the TopicSelector Code option to set the topic the publisher will send a message on. The code checks the message body for the presence of an Xml attribute named “type” in the <Contact> tag. If the attribute is found then the code sets a topic based on the value of the attribute.
The process ends with a Cancel process step named “end message” which is used to simple end the transfer of the original message on the original topic.
Running the Sample
Open the Sample
To open this sample, see the topic Using the Neuron Samples and select the Dynamic Routing Content sample.
Run the Sample
- The sample launcher opens two Neuron Test Clients. Connect one to ContactsPublisher another to ContactsSubscriber.
- From the Repository tab in Neuron Explorer copy the test message VendorContactTestMessageCopy from the Xml Documents area. Copy the test message into the ContactsPublisher test client’s Send tab message field.
- On the Send tab of ContactsPublisher make sure that the Contacts topic is selected in the Topic Dropdown located above the message field then click the Send button.
- View the result in the Receive tab of the ContactsSubscriber test client. Note the Topic field above the message field on the Receive tab. The topic of the message that the ContactsSubscriber received is set to Contacts.Vendor.
Note: The ContactsSubscriber party is configured to receive on topic “Contacts.*” This means that it will receive messages on all subtopics of Contacts. - From the Repository tab in Neuron Explorer copy the test message SalesContactTestMessage from the Xml Documents area. Paste the test message into the ContactsPublisher test client’s Send tab message field.
- Repeat steps 3 and 4.
- Note that this time the topic of the message that the ContactsSubscriber received is set to Contacts.Sales.
Configuration Notes
All processes with the exception of the Code process step are configured by selecting and setting their properties in the property grid located at the bottom right of the process designer. The Code process step is configured by selecting the “Edit” option from the short cut menu that is available when right-clicking the Code step in the process designer. See the process documentation for more information.