This article is about Content-Based Routing principles and the first steps to take to use Content-Based Routing in integration flows. 

What is Content-Based Routing?

Content-Based Routing (CBR) is a messaging pattern to route each message to the correct recipient based on message content as it is described in Enterprise Integration Patterns (G. Hohpe and B. Woolf).

The principle of Content-Based Routing is used the following way. A message with customer data or order is received but not all recipients need to receive the same data, only one or several of them. Data needs to be routed to the correct recipients based on the content. The illustration below explains the principle:

Image above shows a very simple scenario where the Content-Based Routing solves a logistical problem. A new delivery of sports shoes should be routed to the correct store or section for the sports shoes.

Contest-Based Router component

To use Content-Based Routing messaging pattern in your integration flow, select the Content-Based Router component during the design.

Please note: Content-Based Router is an Action component, therefore, it will only be available to choose when the trigger is already added to your integration flow.

For demonstration purposes let us assume that we have an incoming message like this:

  "style": "sport",
  "colour": "red",
  "shoeSize": "41"

Let us just try to route the message based on the value of one of these parameters. After selecting the Content-Based router, we see this screen:

We proceed and add a branch.

Here we can see the incoming data sample and a possibility to write an expression to be evaluated. If the expression is evaluated to a boolean value true, then and only then the message is routed to the corresponding recipient/branch.

Please note: All expressions MUST be evaluated to either boolean value true or false.

The message evaluation is done using the JSONata (JSON query and transformation language). For more information about JSONata please refer to the documentation of the JSONata project.

For this stage, we write a simple expression to select only shoeSize bigger than 41, which is written like this:

$number(shoeSize) > 40

The result is obviously true since the incoming data sample has shoeSize 41. Let us add another branch:

For this branch, we will write the following expression:

$number(shoeSize) <=40

This expression is obviously false for the given incoming data sample. This branch will be used only when the shoeSize is equal to or smaller than 40. Taking this condition into account, we can then add further integration components to the integration flow like this:

We have here a recipient list with a Content-Based routing. Depending on the incoming message, the content will be routed to the branch with E-mail or with Node.js Code component. The choice of components on each branch is arbitrary and depends on your use case.

Content-Based Routing Use cases

Content-Based Routing provides new possibilities to explore many integrations scenarios. Here we list only a few of them to show the capability of this messaging pattern and give you ideas where this can be used.

  • Stock availability query. In this scenario, an arbitrary ERP is always asked for the stock availability and sends an alert if the stock drops below a certain number.
  • Person availability query. In this scenario, an incoming call is made to a switchboard asking for one particular person. The system queries the internal availability status record. Based on that record system, it either connects with the person or replies with an offer to make an appointment for later.
  • Delivery prioritisation. In this scenario, an online shop places an order which gets transferred to packaging and shipping department. Based on the customer's preferences, the shipment is marked as urgent, normal or slow so that the department can prioritise the work for better efficiency.