Content Based Router
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.
...
The following example shows how to route a request from an input queueseda:a endpoint to either queueseda:b, queueseda:c or queueseda:d depending on the evaluation of various Predicate expressions
Using the Fluent Builders
Wiki Markup |
---|
{snippet:id=e3|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java} |
Using the Spring XML Extensions
Wiki Markup |
---|
{snippet:id=e3|lang=xml|url=activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/builder/spring_route_builder_test.xml} |
Code Block | ||
---|---|---|
| ||
RouteBuilder builder = new RouteBuilder() {
public void configure() {
errorHandler(deadLetterChannel("mock:error"));
from("direct:a")
.choice()
.when(header("foo").isEqualTo("bar"))
.to("direct:b")
.when(header("foo").isEqualTo("cheese"))
.to("direct:c")
.otherwise()
.to("direct:d");
}
}; |
Tip |
---|
See Why can I not use when or otherwise in a Java Camel route if you have problems with the Java DSL, accepting using |
Using the Spring XML Extensions
Code Block | ||
---|---|---|
| ||
<camelContext errorHandlerRef="errorHandler" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:a"/>
<choice>
<when>
<xpath>$foo = 'bar'</xpath>
<to uri="direct:b"/>
</when>
<when>
<xpath>$foo = 'cheese'</xpath>
<to uri="direct:c"/>
</when>
<otherwise>
<to uri="direct:d"/>
</otherwise>
</choice>
</route>
</camelContext> |
For further examples of this pattern in use you could look at the junit test case
Include Page | ||||
---|---|---|---|---|
|