简体   繁体   English

只有一个ActiveMQ会话正在处理消息

[英]Only one ActiveMQ session is handling messages

In a project, I am using ActiveMQ to process a relatively large number of messages. 在一个项目中,我正在使用ActiveMQ处理相对大量的消息。 For that purpose there is a queue, fooQueue , which contains the messages to be processed. 为此,有一个队列fooQueue ,其中包含要处理的消息。

Two instances of an application are processing messages from that queue, using Spring JMS. 应用程序的两个实例正在使用Spring JMS处理来自该队列的消息。 I have a DefaultMessageListenerContainer set up in the following way. 我通过以下方式设置了DefaultMessageListenerContainer

DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setDestinationName(QUEUE_NAME);
container.setMessageListener(myMessageListener);
container.setConcurrency(getProperty("concurrency"));
container.setSessionTransacted(true);
container.setErrorHandler(new ErrorHandler());
return container;

By looking at the AMQ web console, I can confirm that the correct number of consumers and sessions are created (session/consumer). 通过查看AMQ Web控制台,我可以确认是否创建了正确数量的使用者和会话(会话/使用者)。 However, it appears as if one session is doing most job, which leads to the application being frozen at times. 但是,似乎一个会话正在完成大多数工作,这导致应用程序有时被冻结。

That session enqueues and dequeues most messages, all others far less then it. 该会话使大多数消息入队和出队,所有其他消息远不及此。 If I restart one of those two application instances, one session in the app instance picks up the work, and behaves the same. 如果我重新启动这两个应用程序实例之一,则该应用程序实例中的一个会话将接管工作,并且行为相同。

Besides checking if myMessageListener is blocking, is there anything else I can do? 除了检查myMessageListener是否被阻止之外,我还能做其他事情吗?

You should take a look at the prefetch settings on your consumers and how it works. 您应该查看使用者的预取设置及其工作方式。 This sounds as though you are starting one instance and it is grabbing a large chunk of messages from the Queue before the others get a chance to. 听起来好像您正在启动一个实例,并且在其他实例获得机会之前,它正在从队列中获取大量消息。 Lowering the prefetch value will lead to a more fair distribution. 降低预取值将导致更公平的分配。

We have tried various settings, increasing the memory, using separate KahaDB instances for every queue etc. but nothing helped. 我们尝试了各种设置,增加了内存,为每个队列使用了单独的KahaDB实例等,但是没有任何帮助。 What helped was to split the queue. 帮助的是拆分队列。

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

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