Dynamic Routing by Header Property
- Neuron ESB
- Samples and Walkthroughs
- Process Samples
- Dynamic Routing by Header Property
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:
- Transform – Xslt
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.
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
- 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.
- 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.
- On the Send tab of TestMessagePublisher make sure that the Orders topic is selected in the Topic Dropdown located above the message field.
- In the Action field on the Send tab of the TestMessagePublisher enter “Orders.Notify” and click the Send button.
- 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.
- Clear the received message from the OrderNotify test client.
- Repeat steps 3 and 4 but enter “Orders.Logging” in the Action field on the TestMessagePublisher test client.
- 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.
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”.