【问题标题】:infinite message delivery loop with activeMQ and Broker Camel Component带有 activeMQ 和 Broker Camel 组件的无限消息传递循环
【发布时间】:2014-07-17 05:34:32
【问题描述】:

我正在使用 activeMQ 5.9。

我正在尝试在我的 activemq.xml 中实现一个拦截类型的路由,我在其中检查特定标头是否等于某个值,然后将其发送到不同的队列,否则允许它继续。

我正在关注这里的信息:http://activemq.apache.org/broker-camel-component.html

我的 camel.xml 文件如下所示:

<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/spring">
    <route id="routeAboveQueueLimitTest">
        <from uri="activemq:queue:do.something"/>
        <choice>
            <when>
                <simple>${header.scope} == 'test'</simple>
                <to uri="activemq:queue:test.do.something"/>
            </when>
            <otherwise>
                <to uri="activemq:queue:do.something"/>
            </otherwise>
        </choice>
    </route>
</camelContext>

然后,当我将消息放在“activemq:queue:do.something”上,标头名为 scope =“test”时,它会正确路由到“activemq:queue:test.do.something”队列。但是,当它没有该标头时,它会将其放回“activemq:queue:do.something”队列并一次又一次地处理它!

这似乎是合乎逻辑的,但上面的页面清楚地表明您必须将其显式发送回代理组件,页面上的第二个示例正好说明了这一点。

我意识到如果它没有标头,可以通过将其发送到不同的队列来解决此问题,但在此阶段这是不可取的。

【问题讨论】:

    标签: apache-camel activemq


    【解决方案1】:

    我认为拦截模式会更适合您正在查看的内容。

        <intercept>
            <when><simple>${header.scope} == 'test'</simple></when>
            <to uri="activemq:queue:test.do.something"/>
        </intercept>
    

    更多信息在这里:http://camel.apache.org/intercept.html

    这将允许没有将范围标头设置为“测试”的消息继续,但将重定向具有测试标头的消息。

    【讨论】:

    • 同意!但我需要将每个队列路由到不同的测试队列。此后我所做的是动态设置 InterceptSendToEndpoint 并将其添加到 camelContext。效果很好!
    【解决方案2】:

    InterceptSendToEndpoint 是一个更好的选择...

    <interceptSendToEndpoint uri="activemq:queue:do.something">
        <when><simple>${header.scope} == 'test'</simple></when>
        <to uri="activemq:queue:test.do.something"/>
        <stop/>
    </interceptSendToEndpoint>
    

    【讨论】:

      猜你喜欢
      • 2018-11-29
      • 1970-01-01
      • 2011-02-11
      • 2021-07-15
      • 2012-09-15
      • 2014-09-24
      • 1970-01-01
      • 2019-04-02
      • 2016-10-24
      相关资源
      最近更新 更多