Annotation DSL Recipient List (Dynamic Router)
When using a Dynamic Router, it implies the usage of a recipient list to control the routing of messages to a designated set of message consumers. We understand that we need to define a channel for each recipient or consumer. The role of the Recipient List is to inspect each inbound message, determine the list of desirable recipients, and forward the message to all channels that are linked with the recipients in our list.
In the following example, we will use the RecipientList annotation to generate our dynamic recipient list.
Â
Annotation DSL Recipient List Example
In this route option, we are using a class (CustomerList) where we use @RecipientList annotation on a method, this will return a single destination based on the customer id.
Â
public class CustomerList {
@RecipientList
public String whereTo(@Header("customerId") id) {
return "jms:queue:customer:" + id;
}
}
NOTE: Notice the flexibility of Camel as it can adapt accordingly to how you define what your methods are returning: a single element, a list, an iterator, etc.
Then, we can route to the bean and it acts as the dynamic list recipient:
from("jms:queue:inbox")
.bean(CustomerList.class, "whereTo");
Â