In Camel 2.5 we introduced a
Dynamic Router in Camel 2.5 onwards
From Camel 2.5 the Dynamic Router will set a property (Exchange.SLIP_ENDPOINT) on the Exchange which contains the current endpoint as it advanced though the slip. This allows you to know how far we have processed in the slip. (It's a slip because the Dynamic Router implementation is based on top of Routing Slip).
In Java DSL you can use the
Which will leverage a Bean to compute the slip on-the-fly, which could be implemented as follows:
Mind that this example is only for show and tell. The current implementation is not thread safe. You would have to store the state on the Exchange, to ensure thread safety, as shown below:
You could also store state as message headers, but they are not guaranteed to be preserved during routing, where as properties on the Exchange are. Although there was a bug in the method call expression, see the warning below.
The same example in Spring XML would be:
You can also use the
Dynamic Router in Camel 2.4 or older
The simplest way to implement this is to use the RecipientList Annotation on a Bean method to determine where to route the message.
The method can be invoked in a number of ways as described in the Bean Integration such as
Using This Pattern
If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.