我有一个Camel路由,它将消息从队列中排掉,发送到bean进行处理,然后将消息排回另一个队列。
我正在努力消除第二个队列中的“重复消息”。骆驼有什么端点,处理器,EIP,等等,我可以配置,在他们被发送到第二队列之前,在途中丢弃消息吗?
示例:
<route id="myRoute">
<from uri="{{queue-1-uri}}" />
<to uri="bean:myBean?method=process" />
<!-- How to dedupe right here??? -->
<to uri="{{queue-2-uri}}" />
</route>更新:可能是这样的:
<route id="myRoute">
<from uri="{{queue-1-uri}}" />
<to uri="bean:myBean?method=process" />
<filter>
<method>what goes here???</method>
<to uri="{{queue-2-uri}}" />
</filter>
</route>根据拉尔夫的建议,我可以在<method></method>中引用一个bean,然后使用缓存将消息保存在内存中。
FilterBean表示,这个新bean名为 dedupe() ,它上有一个方法:如何在Spring中连接它,以及需要实现哪些类/接口从路由内部调用?
发布于 2014-02-13 22:18:15
我想你是在寻找骆驼提供的Idempotent Consumer。有不同的方法取决于您的需要,如内存,JDBC,Hazelcast.我不太确定它是否对你有用,因为你在消费者之后使用bean,但是值得一试。Camel网站的简单例子如下:
<!-- repository for the idempotent consumer -->
<bean id="myRepo" class="org.apache.camel.processor.idempotent.MemoryIdempotentRepository"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<idempotentConsumer messageIdRepositoryRef="myRepo">
<!-- use the messageId header as key for identifying duplicate messages -->
<header>messageId</header>
<!-- if not a duplicate send it to this mock endpoint -->
<to uri="mock:result"/>
</idempotentConsumer>
</route>
</camelContext>您可以在这里找到更多信息:幂等消费者
https://stackoverflow.com/questions/21761470
复制相似问题