首页 文章

Apache Camel / ActiveMQ优先级路由

提问于
浏览
3

我有两个具有相同消费者的AMQ队列 . 第一个队列(Q1)处理97%的消息,而另一个(Q2)仅处理3% . 问题是Q2中的消息需要在排队后立即处理消息 . 所以我的问题是,当Q2中有消息时,我需要以某种方式暂停第一条路线以吸引消费者 . apache camel路由看起来像这样:

<route id="q1">
    <from uri="jms:recordAnalysisRequests" />
    <to uri="bean:analysisService" />
</route>
<route id="q2">
    <from uri="jms:recordAnalysisRequestsFastTrack" />
    <to uri="bean:analysisService" />
</route>

应该采用什么策略?我不认为我可以使用重新排序器,因为Q1可能有数千条排队的消息,而且我无法将所有消息都放在重定序器批处理中 . 我正在看路线限制,但我无法弄清楚如何做到这一点 . 此外,我想知道我是否可以通过zookeeper节点进行同步 . 如果这个解决方案可行,我将需要一些指导 .

1 回答

  • 2

    您可以将所有邮件放在一个队列中并使用邮件优先级http://activemq.apache.org/how-can-i-support-priority-queues.html

    第二个选项,使用Camel Resequencer

    <route id="q1">
        <from uri="jms:recordAnalysisRequests" />
        <setHeader headerName="CustomPriority">
           <constant>2</constant>       
        </setHeader>
        <to uri="direct:analysisDirect" />
    </route>
    <route id="q2">
        <from uri="jms:recordAnalysisRequestsFastTrack" />
        <setHeader headerName="CustomPriority">
           <constant>1</constant>       
        </setHeader>
        <to uri="direct:analysisDirect" />
    </route>
    <route id="q3">
        <from uri="direct:analysisDirect">
        <resequence>
            <header>CustomPriority</header>
            <to uri="bean:analysisService" />
        </resequence>
    </route>
    

    第三个选项(Camel 2.12),而不是使用重定序器,使用带有PriorityBlockingQueue的SEDA endpoints https://camel.apache.org/seda.html#SEDA-ChoosingBlockingQueueimplementation

相关问题