...
In the following example, we see both a 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.
Code Block |
---|
from(<route> <from uri="jms:queue:inbox") /> <multicast> .multicast().to(<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 defined in the message header (mails) that contains the list of recipients as endpoint URLs. Then, the bean processMails is used to add the header[mails] to the message.
...
by performing a method call on a Bean that will provide the list to us dynamically of the recipients.
Code Block | ||
---|---|---|
| ||
<route> <from uri="jms:queue:inbox" /> <recipientList> <method bean="myDynamicRouter" method="route"/> </recipientList> </route> <bean id="myDynamicRouter" .recipientList("destinations");class="com.mycompany.MyDynamicRouter"/> |
Then, in the processMails myDynamicRouter bean, we will use the @Headers annotation we specify a Map object to store route method to return a String object containing all of the recipients for our listpossible destinations.
Code Block |
---|
... public void confirm(@Headers Map headers, @Body String body} {public class myDynamicRouter { public String[] route(String body) { return new String[] recipients ={ "file://backup", .... } headers.put(""destinations", recipients); } } |