Guide to Java DSL (Dynamic Router)

In some situations, we may need to route our messages based on a list of destinations that have been created dynamically, For these types of situations we can use a Dynamic Router that can utilize a self-configuration using a dynamic recipient list. This can be linked to a data store that contains a set of destinations.

In the following example, we see the implementation of a Dynamic Router pattern to determine our destinations through the use of a processor.

 

Java DSL Example

from("jms:queue:order") .processRef(myDynamicRouter) .recipientList("destinations"); public class MyDynamicRouter implements Processor { public void process(Exchange exchange) { // query a data store to find the best match of the // endpoint and return the destination(s) in the // header exchange.getIn() // .setHeader("destinations", list); } }

 

Â