[英]Apache camel: filter / throttle to take just the first message from a queue
從隊列中僅接收第一條消息的最簡單方法是什么?
鑒於我在標題中沒有看到要過濾的內容(沒有序列號之類的東西,至少就我所知),還有什么比這更好的了嗎?
from("webspheremq:topic:SNAPSHOTS")
.throttle(1).timePeriodMillis(1234567890L * 1000)
.to("direct:anotherqueue")
比豆+ Java代碼更喜歡駱駝DSL :)
編輯
實際上是從webspheremq主題閱讀的。
EDIT2
不要使用Long.MAX_VALUE
作為時間段! 請嘗試1234567890L * 1000
您可以嘗試使用持有優先狀態的單例進行過濾:
public static class FirstOrNot {
private static FirstOrNot _instance;
public synchronized boolean isfirst() {
if ( _instance == null ) {
_instance = new FirstOrNot();
return true;
}
return false;
}
}
FirstOrNot first = new FirstOrNot();
from("webspheremq:topic:SNAPSHOTS")
.filter().method( first , "isFirst" )
.to("direct:anotherqueue")
也許您可以以此為起點。
干杯,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.