I am working on a mechanism in Camel that will choose an endpoint for a message from a flag that can be true or false. It's a throttling mechanism that will re-route messages to a bulk ingest endpoint (sent to HDFS) in the case that my upstream channel gets flooded.
Ultimately, my route looks like this:
from("queue:myqueue").bean("messageParser")
.dynamicRoute(bean(ThrottleHelper.class, 'buildEndpoint'));
from('direct:regular').to('hbase');
from('direct:throttle').to('hdfs');
My ThrottleHelper class's buildEndpoint method looks like this:
public static String buildEndpoint() {
synchronized(shouldThrottle) {
if(shouldThrottle)
return "direct:throttle";
else
return "direct:regular"
}
}
Currently, I have a method on the class called checkStatus(); which sets shouldThrottle (a static variable). checkStatus() is run on a Camel quartz timer every minute.
I've noticed some weird behavior and I think I may be misusing this pattern. From further searches on Camel's implementation of the pattern, it looks like buildEndpoint() will be called after each endpoint returned has been traversed by the message. Is this true? Or can I expect that the path will terminate after either going to "direct:throttle" or "direct:regular"?
From what I'm gathering on the web, should my method really look like this?
public static String buildEndpoint(Message message) {
if(message.getHeader('throttled') != null)
return null;
else
message.setHeader('throttled', true);
synchronized(shouldThrottle) {
if(shouldThrottle)
return "direct:throttle";
else
return "direct:regular"
}
}
Thanks!