简体   繁体   English

如何将多个消息一起传递到ActiveMQ中的侦听器?

[英]How to deliver multiple messages together to the Listener in ActiveMQ?

I want 100 messages to be delivered together to a consumer through activemq, but at the same time producer will be producing messages one at a time. 我希望通过activemq将100条消息一起发送给消费者,但同时生产者将一次生成一条消息。

Reason I want this is because I don't want to handle the overhead of processing each message individually on delivery, instead we want to do bulk processing on delivery. 我之所以这样想,是因为我不想处理传递时单独处理每条消息的开销,而是想在传递时进行批量处理。

Is it possible to achieve this through ActiveMQ or should i write my own modifications to achieve this. 是否可以通过ActiveMQ实现此目标,或者我应该编写自己的修改以实现此目标。

ActiveMQ is a JMS 1.1 client / broker implementation therefore there is no API to deliver messages in bulk, the async listener dispatches them one at a time. ActiveMQ是JMS 1.1客户端/代理实现,因此没有API可以批量分发消息,异步侦听器一次分发它们。 The client does prefetch more than one message though so the overhead of processing them using async listeners is quite low. 尽管客户端确实预取了多个消息,所以使用异步侦听器处理消息的开销非常低。

You could achieve your goal by placing every message into a buffer and only doing your processing when the buffer contains N messages. 您可以通过将每个消息放入缓冲区并仅在缓冲区包含N条消息时进行处理来实现您的目标。 To make it work, you'd want to use an acknowledgement mode such as CLIENT_ACKNOWLEDGE that allows you to not acknowledge the messages that are sitting in the buffer until they are processed; 为了使其正常工作,您需要使用一种确认模式,例如CLIENT_ACKNOWLEDGE,它允许您在处理消息之前不确认缓冲区中的消息。 that way if your client crashed with some messages in its memory, they would be re-delivered when the client comes back up. 这样,如果您的客户端崩溃时在其内存中存有一些消息,则在客户端恢复时将重新发送它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM