When

The When EIP is related to Content Based Router from the EIP patterns

image

Options

The When eip has no options.

Examples

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

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        from("direct:a")
            .choice()
                .when(simple("${header.foo} == 'bar'"))
                    .to("direct:b")
                .when(simple("${header.foo} == 'cheese'"))
                    .to("direct:c")
                .otherwise()
                    .to("direct:d");
    }
};

And the same example using XML:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:a"/>
        <choice>
            <when>
                <simple>${header.foo} == 'bar'</simple>
                <to uri="direct:b"/>
            </when>
            <when>
                <simple>${header.foo} == 'cheese'</simple>
                <to uri="direct:c"/>
            </when>
            <otherwise>
                <to uri="direct:d"/>
            </otherwise>
        </choice>
    </route>
</camelContext>