Proper use of SpringRabbit DirectMessageListenerContainer and setConsumersPerQueue property

限于喜欢 提交于 2020-02-06 08:08:33

问题


I use the DirectMessageListenerContainer to listen to individual queues, since it creates a consumer per queue, preventing queue starvation if a messages on say "queue1" take a while to process, while the one on "queue2" are quick to process. I am confused about the DirectMessageListenerContainer.setConsumersPerQueue method. The default value is 1 looking at the source code.

Under what conditions would one need to increase it to greater than 1? If left to default value of 1, is the processing of messages done in a multithreaded way for a given queue, if fetch size is greater than 1?

    DirectMessageListenerContainer
        listenerContainer =
        new DirectMessageListenerContainer(connectionFactory);

    listenerContainer.setConsumersPerQueue(10);
    listenerContainer.addQueueNames("queue1","queue2");


回答1:


It's to increase concurrency; for example if your listener is slow, and you don't care about message ordering, you can assign multiple consumers to the same queue and process messages in parallel. Depending on your message count, you may need to reduce the prefetch count so that one consumer doesn't "grab" all the messages during startup.

The prefetch size has no effect on concurrency; it is just that; prefetch.



来源:https://stackoverflow.com/questions/59975870/proper-use-of-springrabbit-directmessagelistenercontainer-and-setconsumersperque

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!