【问题标题】:Camel EIP to filter duplicatesCamel EIP 过滤重复项
【发布时间】:2014-03-12 18:11:45
【问题描述】:

我有一个 Camel 路由,可以将消息从队列中取出,将其发送到 bean 进行处理,然后将消息重新放入另一个队列中。

我正在尝试消除第二个队列中的“重复消息”。在将消息发送到第二个队列之前,Camel 是否有任何端点、处理器、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>

根据 Ralf 的建议,我可以在 &lt;method&gt;&lt;/method&gt; 中引用一个 bean,然后使用缓存将消息保存在内存中。

假设这个新 bean 被称为 FilterBean,它有一个 dedupe() 方法:我如何在 Spring XML 中连接它,以及 bean 需要实现哪些类/接口从路线内部调用?

【问题讨论】:

  • 您可以使用支持分布式部署的缓存(如 EHCache 或 memcached)作为Message Filter 的后端服务。
  • 感谢@Ralf (+1) - 请查看我的更新。关于我需要如何为FilterBean 实现什么 API/接口以及如何在 Spring XML 中连接它的任何想法?再次感谢!

标签: java apache-camel esb integration-patterns


【解决方案1】:

我认为您正在寻找 Camel 提供的Idempotent Consumer。根据您的需要有不同的方法,例如内存、JDBCHazelcast...我不确定它是否适合您,因为您在消费者之后使用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>

您可以在这里找到更多信息:Idempotent Consumer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 2021-09-27
    • 2013-05-23
    • 2018-04-26
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    相关资源
    最近更新 更多