The Content Based Router from the EIP patterns allows you to route messages to the correct destination based on the contents of the message exchanges.


Choice options

The Choice EIP supports 2 options which are listed below:

Name Description Default Type


Sets the when clauses



Sets the otherwise node



The following example shows how to route a request from an input seda:a endpoint to either seda:b, seda:c or seda:d depending on the evaluation of various Predicate expressions

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
                .when(simple("${} == 'bar'"))
                .when(simple("${} == 'cheese'"))

And the same example using XML:

<camelContext xmlns="">
        <from uri="direct:a"/>
                <simple>${} == 'bar'</simple>
                <to uri="direct:b"/>
                <simple>${} == 'cheese'</simple>
                <to uri="direct:c"/>
                <to uri="direct:d"/>

Usage of endChoice and end

Usage of endChoice is not mandatory. However, It should be used whenever you want to return back control to choice() dsl so that you can add subsequent when and otherwise to the choice dsl. If you want to end entire choice() block use end().


    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                        .endChoice() //we need to use endChoice to tell Java DSL to return scope back to the choice DSL.

Another example is explained in the TIP below.

See Why can I not use when or otherwise in a Java Camel route if you have problems with the Java DSL, accepting using when or otherwise.