与ActiveMQ的并行处理多个消息 [英] Processing multiple message in parallel with ActiveMQ
问题描述
我想并行处理使用一个简单的处理器/ AsyncProcessor为目的地的队列中的消息。处理器采用每个消息一点时间,但是每个消息可以单独同时进行处理,因此,(健康的界限内)。
I'd like to process messages in a queue in parallel using a simple Processor/AsyncProcessor as a destination. The processor takes a little time per message, but each message can be handled seperately, and thus at the same time (within healthy boundaries).
我有一个很难找到的例子,尤其是关于骆驼航线的xml配置。
I'm having a hard time finding examples, especially about the xml configuration of camel routes.
到目前为止,我已经定义了一个线程池,路线和处理器:
So far, I've defined a threadpool, route and processor:
<threadPool id="smallPool" threadName="MyProcessorThread" poolSize="5" maxPoolSize="50" maxQueueSize="100"/>
<route>
<from uri="broker:queue:inbox" />
<threads executorServiceRef="smallPool">
<to uri="MyProcessor" />
</threads>
</route>
<bean id="MyProcessor" class="com.example.java.MyProcessor" />
和我的处理器是这样的:
and my processor looks like:
public class MyProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String msg = in.getBody(String.class);
System.out.println(msg);
try {
Thread.sleep(10 * 1000); // Do something in the background
} catch (InterruptedException e) {}
System.out.println("Done!");
}
}
不幸的是,当我发帖的队列,他们仍然处理一个接一个,每10秒(我的后台任务)。
Unfortunatly, when I post messages to the queue, they are still processed one by one, each delayed by 10 seconds (my "background task").
任何人都可以点我到正确的方向上的邮件,使用线程池定义或解释什么,我做错了受理?
Can anyone point me to the right direction to have the messages processed using the defined threadpool or explain what I am doing wrong?
推荐答案
您应该说使用concurrentConsumers选项中的注释
You should use the concurrentConsumers options as said in the comments,
<route>
<from uri="broker:queue:inbox?concurrentConsumers=5" />
<to uri="MyProcessor" />
</route>
的通知也有 maxConcurrentConsumers
您可以设置为使用最小/最大范围并发的消费者,所以骆驼会自动生长/根据负载萎缩。
Notice there is also maxConcurrentConsumers
you can set to use a min/max range of concurrent consumers, so Camel will automatic grow/shrink depending on load.
请参阅在JMS文档的详细信息在
See more details in the JMS docs at
- http://camel.apache.org/jms
这篇关于与ActiveMQ的并行处理多个消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!