This week, we’ll study a variation of Message Router pattern known as Content-based Router.
When do I use this pattern?
This pattern can be applied when the message needs to be routed based on the contents of the message. For example, if a delivery is to be done in the UK, it is sent to Delivery System in the UK, if the delivery is to be done in India, it is sent to Delivery System in India. In this example, the value of the Country element can be used to send a message to one system or another.
Content-based Router in CPI
As in the Message Router pattern blog, Content-based Router in CPI is implemented using Router component. In the Message Router pattern blog, the example of routing the IDoc based on the value of IDOCTYP element is an example of Content-based Router.
In this blog, we’ll focus on sending a message into a different Delivery System based on the content of the Country element.
Let’s consider these two payloads:
<Delivery> <Country>UK</Country> </Delivery>
<Delivery> <Country>India</Country> </Delivery>
Here, the DS is a central delivery system sending deliveries to delivery systems in each country.
The routing has been achieved using the Router ‘Country’. Here’s the configuration of the Routing Condition table:
|Order||Route Name||Condition Expression||Default Route|
|1||India||/Delivery/Country = ‘India’||No|
|2||UK||/Delivery/Country = ‘UK’||No|
Content-based Router is a type of Message Router that is used, as the name suggests when a message needs to be routed based on the contents of the message. In CPI, use the Router component to implement Content-based Routing.
- Content-based Router in Enterprise Integration Patterns
- EIPinCPI: Message Router
- Alex‘s blog on Content-based Routing
- CPI Components
Hope this helps,
P.S.: Alex has already blogged about Content-based Routing. We both are using a similar example to demonstrate Content-based Routing in CPI. Read Alex’s blog to learn about implementing Content-based Routing in Process Orchestration as well as in CPI.