Recipient ListPage edited by Claus IbsenRecipient ListThe Recipient List from the EIP patterns allows you to route messages to a number of dynamically specified recipients. The recipients will receive a copy of the same Exchange and Camel will execute them sequentially. Static Recipient ListThe following example shows how to route a request from an input queue:a endpoint to a static list of destinations Using Annotations Using the Fluent Builders RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); from("seda:a").multicast().to("seda:b", "seda:c", "seda:d"); } }; Using the Spring XML Extensions <camelContext errorHandlerRef="errorHandler" streamCache="false" id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="seda:a"/> <multicast> <to uri="seda:b"/> <to uri="seda:c"/> <to uri="seda:d"/> </multicast> </route> </camelContext> Dynamic Recipient ListUsually one of the main reasons for using the Recipient List pattern is that the list of recipients is dynamic and calculated at runtime. The following example demonstrates how to create a dynamic recipient list using an _expression_ (which in this case it extracts a named header value dynamically) to calculate the list of endpoints which are either of type Endpoint or are converted to a String and then resolved using the endpoint URIs. Using the Fluent Builders RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); from("seda:a").recipientList(header("foo")); } }; The above assumes that the header contains a list of endpoint URIs. The following takes a single string header and tokenizes it from("direct:a").recipientList( header("recipientListHeader").tokenize(",")); Iteratable valueThe dynamic list of recipients that are defined in the header must be iteratable such as:
Using the Spring XML Extensions <camelContext errorHandlerRef="errorHandler" streamCache="false" id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="seda:a"/> <recipientList> <xpath>$foo</xpath> </recipientList> </route> </camelContext> For further examples of this pattern in use you could look at one of the junit test case Using delimiter in Spring XMLAvailable as of Camel 1.5.1 <route> <from uri="direct:a" /> <!-- use comma as a delimiter for String based values --> <recipientList delimiter=","> <header>myHeader</header> </recipientList> </route> So if myHeader contains a String with the value "activemq:queue:foo, activemq:topic:hello , log:bar" then Camel will split the String using the delimiter given in the XML that was comma, resulting into 3 endpoints to send to. You can use spaces between the endpoints as Camel will trim the value when it lookup the endpoint to send to. Note: In Java DSL you use the tokenizer to archive the same. The route above in Java DSL: from("direct:a").recipientList(header("myHeader").tokenize(",")); In Camel 2.1 its a bit easier as you can pass in the delimiter as 2nd parameter: from("direct:a").recipientList(header("myHeader"), "#"); Using This PatternIf 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.
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > Recipient List confluence
- [CONF] Apache Camel > Recipient List confluence
- [CONF] Apache Camel > Recipient List confluence
- [CONF] Apache Camel > Recipient List confluence
- [CONF] Apache Camel > Recipient List confluence
- [CONF] Apache Camel > Recipient List confluence