我正在駱駝的一個機制,將選擇一個標誌,可以是true或false的消息端點。這是一種限制機制,在我的上行信道被淹沒的情況下,將消息重新路由到批量接收端點(發送到HDFS)。動態路由在駱駝
最終,我的路線是這樣的:
from("queue:myqueue").bean("messageParser")
.dynamicRoute(bean(ThrottleHelper.class, 'buildEndpoint'));
from('direct:regular').to('hbase');
from('direct:throttle').to('hdfs');
我ThrottleHelper類的buildEndpoint方法是這樣的:
public static String buildEndpoint() {
synchronized(shouldThrottle) {
if(shouldThrottle)
return "direct:throttle";
else
return "direct:regular"
}
}
目前,我對所謂的checkStatus()類的方法;其中設置的應該是Tottle(一個靜態變量)。 checkStatus()每分鐘在一個Camel石英計時器上運行。
我注意到了一些奇怪的行爲,我想我可能會濫用這種模式。通過對Camel實現該模式的進一步搜索,看起來buildEndpoint()將在消息遍歷每個返回的端點之後調用。這是真的?或者,我是否可以預期在「direct:throttle」或「direct:regular」之後路徑會終止?
從我在網上收集的信息看,我的方法應該看起來像這樣嗎?
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"
}
}
謝謝!
沒關係。我用單元測試驗證了這種行爲。我列出的第二種方法(測試以查看方法是否已被調用)有效。 我的下一個問題 - 爲什麼我會使用dynamicRouter,而不是讓我的ThrottleHelper使用「shouldThrottle」屬性來豐富每個消息的頭並使用基於該頭部屬性的基於內容的路由? –