Skip to content

Dynamic Routing by Header Property

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 Decision Neuron Process step to route a message to different topics based on the value of an ESB Message property. A Decision process step contains 2 to n branches each of which can contain any number of other process steps. There is at least 1 conditional “If” branch and 1 “Else” branch in a Decision process step. Any number of “Else If” conditional branches may be added. The evaluation is always done from left to right starting with “If” branch then continuing through each “Else If” branch and finally ending up at the “Else” branch if no preceding condition is met. Conditions are specified in the branch as code similar to the Code process step.

Process Components Demonstrated:

  • Decision
  • Transform – Xslt
  • Publish
  • Cancel

Solution

The Dynamic Topic Routing – Header process depicted in Figure 2 has a Decision process step that is used as a container for all other steps in the process.

The first conditional branch (shown as “Notify = True”) contains a Transform – Xslt process step named “order to html” that will be used to alter the message body into an HTML form that could be used in an Email for example. This branch also contains a Publish process step named “notify orders” that will send the transformed message on a subtopic of Orders named “Orders.Notify”.

The second conditional branch (shown as “Logging = True”) contains a Transform – Xslt process step named “order plain” that will be used to alter the message body into plain text that may, for example, be used to log to a disk file. This branch also contains a Publish process step named “log orders” that will send the altered message on a subtopic of Orders named “Orders.Logging”.

The last branch (shown as “Else”) contains a Cancel process step named “cancel message”. A Cancel process step ends a process and ends the delivery of the original message. It does not cause the process to abort and log an error. Instead it is used to simply end the process and the message transfer.

Finally, the entire Decide step is contained within an Exception step. If an error occurs at runtime, the Exception Handling process is called to handle the exception.

Figure 1: Empty Decision process step as displayed in the Neuron Process Designer.
Figure 2: Completed Dynamic Topic Routing process as displayed in the Neuron Process Designer.

In each of the two condition branches, the expression evaluated is specified in code (C#). The code checks the ESB Message context property, Action. If the Action property is set to “Orders.Notify” the process execution will follow the “Notify = True” branch. If the Action property is set to “Orders.Logging” the process execution will follow the “Logging = True” branch. Any other value in the Action property will send the process execution down the “Else” branch and the Cancel process step will end the message transfer.

Running the Sample

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the Dynamic Routing Header Properties sample.

Run the Sample

  1. The sample launcher opens 4 Neuron Test Clients. Connect one to TestMessagePublisher another to OrdersPublisher another to OrderNotify and the final test client to OrderLogger.
  2. From the Repository tab in Neuron Explorer copy the test message OrdersTestMessage from the Xml Documents area. Paste the test message into the TestMessagePublisher test client’s Send tab message field.
  3. On the Send tab of TestMessagePublisher make sure that the Orders topic is selected in the Topic Dropdown located above the message field.
  4. In the Action field on the Send tab of the TestMessagePublisher enter “Orders.Notify” and click the Send button.
  5. View the result in the Receive tab of the OrderNotify test client. You should see the html result in the message window. Also view the Receive tab of the OrderLogger test client and note that no message was received.
    Note: The html message will also be visible in the message window of the OrdersPublisher test client because it is authorized to receive messages from the Orders topic as well as any sub topic of Orders (i.e. Orders.*).
  6. Clear the received message from the OrderNotify test client.
  7. Repeat steps 3 and 4 but enter “Orders.Logging” in the Action field on the TestMessagePublisher test client.
  8. View the result in the Receive tab of the OrderLogger test client. You should see the text result in the message window. Also view the Receive tab of the OrderNotify test client and note that no message was received.

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 3: The Neuron Process Designer displaying the Dynamic Topic Routing process. Property Grid at the bottom right displaying the properties for the Transform – Xslt process step named “order to html”.

Was this article helpful?
Dislike 0
Previous: Dynamic Routing by Content
Next: Exception Handling