5.5. Message Router

download PDF


A message router, shown in Figure 5.7, “Message Router Pattern”, is a type of filter that consumes messages from a single consumer endpoint and redirects them to the appropriate target endpoint, based on a particular decision criterion. A message router is concerned only with redirecting messages; it does not modify the message content.

Figure 5.7. Message Router Pattern

Message router pattern
A message router can easily be implemented in Apache Camel using the choice() processor, where each of the alternative target endpoints can be selected using a when() subclause (for details of the choice processor, see Section 1.5, “Processors”).

Java DSL example

The following Java DSL example shows how to route messages to three alternative destinations (either seda:a, seda:b, or seda:c) depending on the contents of the foo header:

XML configuration example

The following example shows how to configure the same route in XML:
<camelContext id="buildSimpleRouteWithChoice" xmlns="">
    <from uri="seda:a"/>
        <xpath>$foo = 'bar'</xpath>
        <to uri="seda:b"/>
        <xpath>$foo = 'cheese'</xpath>
        <to uri="seda:c"/>
        <to uri="seda:d"/>

Choice without otherwise

If you use choice() without an otherwise() clause, any unmatched exchanges are dropped by default.
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.