Guide to Java DSL (Content-based Router)

In some scenarios, a single logical process and its implementation (ie. price check), could be spread across many different physical systems. We need to ensure that the message is being sent to the correct consumer using information contained with the message itself.

In the following example, we see the implementation of a Content-based Router pattern to route the message to the correct consumer using the Choice option.

 

Java DSL Example

from("jms:queue:order") .choice() .when(header("type").in("widget","wiggy")) .to("jms:queue:order:widget") .when(header("type").isEqualTo("gadget")) .to("jms:queue:order:gadget") .otherwise().to("jms:queue:order:misc") .end();

NOTE: In the route example above, end() can be omitted since it is the last node and we don’t need to route the message to a new destination after the choice option has been executed. Also, we can continue routing after the choice ends.