EIPinCPI – Message Router

December 15, 2019 Bhalchandra Wadekar

This week, we’ll study yet another Message Routing pattern called Message Router.

When do I use this pattern?

A router is a type of a filter in integration patterns. The router, as the name suggests, routes the incoming message to a specified channel based on a condition. The router will not change the message.

Message Router in CPI

Message Router is implemented in CPI using the Router component. The router in CPI can route the message based on XML conditions or Non-XML conditions.

I’ll use the example of routing based on the IDoc Type and demonstrate how to achieve that using XML and Non-XML conditions. Let’s consider that orders are sent to Order Management System (OMS) and deliveries are sent to Delivery System (DS). Let’s use IDoc ORDERS05 and IDoc DELVRY07 for orders and deliveries respectively without any extensions.

XML conditions

When using XML conditions XPath is used to check the condition. In our example of checking the IDoc Type of the message, the XPath ‘//IDOCTYP’ can be checked.

Here’s the configuration of Routing Condition table of the Router ‘Type?’:

Order Route Name Condition Expression Default Route
3 Default   Yes

Non-XML conditions

The Non-XML conditions are written using Apache Camel’s Simple Language. The step “Is First Chunk?” in Message Sequence pattern blog is also an example of a CPI Router using a Non-XML condition.

Coming back to the example in this blog, the IDoc Type can be checked using the header ‘SapIDocType’ set by the IDoc Sender Adapter.

The integration flow will look exactly the same. However, the configuration of the Routing Condition table of the Router ‘Type?’ is as follows:

Order Route Name Condition Expression Default Route
1 ORDERS05 ${header.SapIDocType} = ‘ORDERS05’ No
2 DELVRY07 ${header.SapIDocType} = ‘DELVRY07’ No
3 Default   Yes


The Router is a type of filter that routes the message based on a condition. In CPI, the routing conditions can be written using XPath expression or Apache Camel’s Simple Language using the Router component.

References/Further Readings

Hope this helps,

About the Author

Bhalchandra Wadekar

Bhalchandra Wadekar is an Integration Enthusiast who authored the Enterprise Integration Patterns in SAP Cloud Platform Integration (#EIPinCPI) series on SAP Blog Community. He is a fan of integration from API Management and Open Connectors to Message Based Integration and Data Integration.

More Content by Bhalchandra Wadekar
Previous Article
EIPinCPI – Recipient List
EIPinCPI – Recipient List

Next Article
EIPinCPI – Message Filter
EIPinCPI – Message Filter