Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
bhalchandraswcg
Contributor

Previous - Pipes-and-Filters | Index | Next - Content-based Router


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
1 ORDERS05 //IDOCTYP = 'ORDERS05' No
2 DELVRY07 //IDOCTYP = 'DELVRY07' No
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

Conclusion


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,
Bala

Previous - Pipes-and-Filters | Index | Next - Content-based Router

Labels in this area