Skip to content

Dynamic Routing by Content

Note: It is recommended that the Neuron process documentation be reviewed before running this sample. The documentation thoroughly describes each process component individually and describes how to configure each one as well as how to construct a process and associate it with a Neuron Publisher or Subscriber. See the Configuration Notes section at the end of this document for more information.

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.

Figure 1: Dynamic Topic Routing – Content process as displayed in the Neuron Process Designer.

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.

Note: See figures 3 and 4 for more information regarding the TopicSelector Code option property configured for the “contact selector pub” Publish process step.

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

  1. The sample launcher opens two Neuron Test Clients. Connect one to ContactsPublisher another to ContactsSubscriber.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Repeat steps 3 and 4.
  7. 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.

Figure 2: The Neuron Process Designer displaying the Dynamic Topic Routing – Content process. Property Grid at the bottom right displaying the properties for the Publish process step named “contact selector pub”.
Figure 3: The property grid for the “contact selector pub” Publish process step. The Selector type is set to use Code. The Code is edited by clicking the ellipsis button to the right of the (TopicSelector Code) property.
Figure 4: The code for the topic selection from the “contact selector pub” Publish process step.
Was this article helpful?
Dislike 0
Previous: Correlated Messaging with the MSMQ Process Step
Next: Dynamic Routing by Header Property