|
Page Edited :
CAMEL :
RecipientList Annotation
RecipientList Annotation has been edited by James Strachan (Oct 02, 2008). Content:@RecipientList AnnotationAs of 1.5.0 we now support the use of @RecipientList on a bean method to easily create a dynamic Recipient List using a Java method. Simple Example using @Consumepublic class RouterBean {
@Consume(uri = "activemq:foo")
@RecipientList
public String[] route(String body) {
return new String[]{"activemq:bar", "activemq:whatnot"};
}
}
For example if the above bean is configured in Spring when using a <camelContext> element, a route will be created consuming from the foo queue on the ActiveMQ component which when a message is received the How it worksThe return value of the @RecipientList method is converted to either a java.util.Collection / java.util.Iterator or array of objects where each element is converted to an Endpoint or a String, or if you are only going to route to a single endpoint then just return either an Endpoint object or an object that can be converted to a String Then for each endpoint or URI the message is forwarded a separate copy. You can then use whatever Java code you wish to figure out what endpoints to route to; for example you can use the Bean Binding annotations to inject parts of the message body or headers or use _expression_ values on the message. More Complex Example Using DSLIn this example we will use more complex Bean Binding, plus we will use a separate route to invoke the Recipient List public class RouterBean2 { @RecipientList public String route(@Header("customerID") String custID String body) { if (custID == null) return null; return "activemq:Customers.Orders." + custID; } } public class MyRouteBuilder extends RouteBuilder { protected void configure() { from("activemq:Orders.Incoming").beanRef("myRouterBean", "route"); } } Notice how we are injecting some headers or expressions and using them to determine the recipients. See the Bean Integration for more details. |
Unsubscribe or edit your notifications preferences
