Assume that we are building an order processing system. When an incoming order is received, we first validate the order and then verify that the ordered item is available in the warehouse. This function is performed by the inventory system. This sequence of processing steps is a perfect candidate for the Pipes and Filters style. We create two filters, one for the validation step and one for the inventory system, and route the incoming messages through both filters. However, in many enterprise integration scenarios more than one inventory system exists with each system being able to handle only specific items. How do we handle a situation where the implementation of a single logical function (e.g., inventory check) is spread across multiple physical systems? Use a Content-Based Router to route each message to the correct recipient based on message content. The Content-Based Router examines the message content and routes the message onto a different channel based on data contained in the message. The routing can be based on a number of criteria such as existence of fields, specific field values etc. When implementing a Content-Based Router, special caution should be taken to make the routing function easy to maintain as the router can become a point of frequent maintenance. In more sophisticated integration scenarios, the Content-Based Router can take on the form of a configurable rules engine that computes the destination channel based on a set of configurable rules. ...Example: Apache CamelNEWMany open source ESBs like Apache Camel have direct support for many Enterprise Integration Patterns, wither in a Java-based DSL or as configuration. For example, setting up a Content-Based Router in Camel is quite easy and idiomatic by using a RouteBuilder: RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); from("direct:in") .choice() .when(header("type").isEqualTo("widget")) .to("direct:widget") .when(header("type").isEqualTo("gadget")) .to("direct:gadget") .otherwise() .to("direct:other"); } }; Related patterns: Dynamic Router, Message Filter, Invalid Message Channel, Message Router, Pipes and Filters, Publish-Subscribe Channel, Routing Slip, Transactional Client |
Want to keep up-to-date? Follow My Blog.
Want to read more in depth? Check out My Articles.
Want to see me live? See where I am speaking next.
![]() Find the full description of this pattern in: | From Enterprise Integration to Enterprise Transformation: My new book describes how architects can play a critical role in IT transformation by applying their technical, communication, and organizational skills with 37 episodes from large-scale enterprise IT. |
![]() Parts of this page are made available under the Creative Commons Attribution license. You can reuse the pattern icon, the pattern name, the problem and solution statements (in bold), and the sketch under this license. Other portions of the text, such as text chapters or the full pattern text, are protected by copyright. |
© 2003, 2019 • Bobby Woolf • All rights reserved. |