Message Router
The Message Router from the EIP patterns allows you to consume from an input destination, evaluate some predicate then choose the right output destination.
The following example shows how to route a request from an input queue:a endpoint to either queue:b, queue:c or queue:d depending on the evaluation of various Predicate expressions
Examples
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() {
from("direct:a")
.choice()
.when(simple("${header.foo} == 'bar'"))
.to("direct:b")
.when(simple("${header.foo} == 'cheese'"))
.to("direct:c")
.otherwise()
.to("direct:d");
}
};
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 .
|
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>