apache-camel - Apache Camel/ActiveMQ 优先路由

标签 apache-camel activemq

我有两个具有相同消费者的 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 节点同步。如果此解决方案可行,我将再次需要一些指导。

最佳答案

您可以将所有消息放在一个队列中并使用消息优先级 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 端点 https://camel.apache.org/seda.html#SEDA-ChoosingBlockingQueueimplementation

关于apache-camel - Apache Camel/ActiveMQ 优先路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22984449/

相关文章:

java - 为什么这个简单的 JSON 编码示例在 Apache Camel 中不起作用?

java - 使用特定于路由的 DLQ 配置 Java/Camel/AMQ

java - Spring JMS ActiveMQ 跟踪作业状态

java - 发送 JSON 到服务器

java - 如何在运行时切换绑定(bind) (Camel Rest Dsl)

java - CamelContext 已加载,但路由定义为空

activemq - 如何在 ActiveMq 中设置最大消息大小

java - JMS 自动确认消费者处理发生在 onMessage 中

java - 与 Windows 相比,ActiveMQ FailoverTransport 在 Linux 上重新连接的速度太快

java - Apache Camel 测试在使用camel-archetype-blueprint 创建的项目中失败