@RecipientList Annotation
As of 1.5.0 we now We support the use of @RecipientList on a bean method to easily create a dynamic Recipient List using a Java method.
Simple Example using @Consume and @RecipientList
Code Block |
---|
|
package com.acme.foo;
public 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 as follows
Code Block |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"/>
<bean id="myRecipientList" class="com.acme.foo.RouterBean"/>
</beans>
|
then , a route will be created consuming from the foo queue on the ActiveMQ component which when a message is received the
message will be forwarded to the endpoints defined by the result of this method call - namely the bar and whatnot queues.
...
Code Block |
---|
|
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").beanRefrecipientList(bean("myRouterBean", "route"));
}
}
|
Notice how we are injecting some headers or expressions and using them to determine the recipients using Recipient List EIP.
See the Bean Integration for more details.