I am working on camel’s dynamic router to derive and dispatch to the relevant queue by referring http://camel.apache.org/dynamic-router.html
Following is the camel config xml:
<route id="dynamicRouter" autoStartup="true">
<from uri="vm://service1?concurrentConsumers=10&timeout=0" />
<choice>
<when>
<simple>${body.documentStatus} == 'SUCCESS' </simple>
<log message="routing to dynamic router" />
<dynamicRouter>
<!-- use a method call on a bean as dynamic router -->
<method ref="messageRouter" method="route" />
</dynamicRouter>
</when>
</choice>
</route>
Following is my dynamic router bean:
public class MessageRouter {
private static final String QUEUE_BROKER = "activemq";
private static final String DEFAULT_QUEUE = "queue";
/**
*
* @param obj
* message
* @return the dynamically generated queue name
*/
public String route(ServiceObject obj) {
RecordObject record = obj.getRecordObject();
if(record != null){
return QUEUE_BROKER + ":"
+ record.getId() + "." + DEFAULT_QUEUE;
}
return null;
}
}
I am able to en-queue messages in dynamically created queue but messages are getting enqueued infinitely.
Any help in identifying what could be the reason would be of great help.
Thanks in advance!!!
Read the documentation about dynamic router at
And see the beware box, it says the method must return
null
to signal to the dynamic router to break out.So in your code above, then this code line
... the
record
object is nevernull
and therefore the dynamic router keeps going forever.If you only want this dynamic routing one time then use the dynamic receipient list eip instead, see
And your xml route is