/
XML DSL Recipient List (Dynamic Router)

XML 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 see both an XML DSL static and dynamic implementation of our recipient list.

 

XML DSL Recipient List Static Example

In this route option, we are routing to a static list of just two different recipients, both of them will receive a copy of the same message simultaneously.

<route> <from uri="jms:queue:inbox" /> <multicast> <to uri="file://backup"/> <to uri="accounting:inbox"/> </multicast> </route>

Note: Camel supports the use of the static Recipient List using the multicast node, and with the dynamic Recipient List we can employ the recipientList node.

 

XML DSL Recipient List Dynamic Example

In this route option, we are routing to a dynamic list of recipients by performing a method call on a Bean that will provide the list to us dynamically of the recipients.

<route> <from uri="jms:queue:inbox" /> <recipientList> <method bean="myDynamicRouter" method="route"/> </recipientList> </route> <bean id="myDynamicRouter" class="com.mycompany.MyDynamicRouter"/>

Then, in the myDynamicRouter bean, we will use the route method to return a String object containing all of the possible destinations.

public class myDynamicRouter { public String[] route(String body) { return new String[] { "file://backup", .... } } }

 

 

Related content

Java DSL Recipient List (Dynamic Router)
Java DSL Recipient List (Dynamic Router)
More like this
Annotation DSL Recipient List (Dynamic Router)
Annotation DSL Recipient List (Dynamic Router)
More like this