首页 文章

Camel中来自同一来源的多条路线

提问于
浏览
1

我有一个包含多个消费者的JMS队列 . 我正在尝试跟随骆驼路线,

<camel:camelContext id="camel-server">
        <camel:package>com.camlin.consumer</camel:package>

        <camel:route id="one">
            <camel:from uri="jms:queue:request" />
            <camel:choice>
                <camel:when>
                    <camel:simple>${header.type} == '1'</camel:simple>
                    <camel:to uri="bean:consumerBean?method=receive1" />
                </camel:when>
            </camel:choice>
        </camel:route>

        <camel:route id="two">
            <camel:from uri="jms:queue:request" />
            <camel:choice>
                <camel:when>
                    <camel:simple>${header.type} == '2'</camel:simple>
                    <camel:to uri="bean:consumerBean?method=receive2" />
                </camel:when>
            </camel:choice>
        </camel:route>

    </camel:camelContext>

消息作为,

producer.sendBodyAndHeader("Hello from Producer-1", "type", "1");
producer.sendBodyAndHeader("Hello from Producer-2", "type", "2");

仅消耗第一条消息 . 第二条消息永远不会按路由到达consumerBean . Q1. Any missing configuration here?

我想拥有多条路由,因为我需要动态添加/删除路由 . 因此,拥有多个选择的单一路线并不适用于此 .

Q2. When camel inspects a message by header whether it is removed from the queue? So that it is not available to other route? 更新:请参阅http://fusesource.com/docs/router/2.5/eip/MsgEnd-Selective.html . 过滤器通过消费消息来工作 . 所以选择器只是选项 .

1 回答

  • 2

    如果您希望所有路由(消费者)都接收所有消息,那么您需要订阅主题 . 队列中的消息只能使用一次 . 关于主题的消息被传递给所有订阅的消费者 .

    如果要使用队列,可以使用JMS选择器 . 但是,选择器是一个 endpoints 选项,您尚未在代码段中设置该选项 .

相关问题