简体   繁体   中英

Only one ActiveMQ session is handling messages

In a project, I am using ActiveMQ to process a relatively large number of messages. For that purpose there is a queue, fooQueue , which contains the messages to be processed.

Two instances of an application are processing messages from that queue, using Spring JMS. I have a DefaultMessageListenerContainer set up in the following way.

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). 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?

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. What helped was to split the queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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