Enterprise Integration Patterns
Messaging Patterns
HOME PATTERNS RAMBLINGS ARTICLES TALKS DOWNLOAD BOOKS CONTACT
Messaging Patterns
Content-Based RouterContent-Based RouterMessaging Patterns » Message Routing

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.

... Read the entire pattern in the book Enterprise Integration Patterns

Example: Apache CamelNEW

Many 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


Creative Commons Attribution License

You can reuse the following elements under the Creative Commons Attribution license: pattern icon, pattern name, problem and solution statements (in bold), and the sketch. Other portions are protected by copyright.

Enterprise Integration Patterns book cover

Enterprise Integration Patterns
The de-facto language for designing asynchronous, distributed systems. Over 100,000 copies sold.

Software Architect Elevator book cover

The Software Architect Elevator
Rethink the role of architects as a connecting element across organizational layers. Acquire the technical, communication, and organizational skills to succeed in this new role.

Cloud Strategy book cover

Cloud Strategy
Make your cloud migration a success by translating high-level goals into conscious decisions with well-understood trade-offs.

Platform Strategy book cover

Platform Strategy
Platforms can boost innovation through harmonization, but they aren't easy to build. Learn from over a decade of designing and rolling out IT platforms.