This article is a mirror article of machine translation, please click here to jump to the original article.

View: 23648|Reply: 0

RabbitMQ BasicQos consumer parallel processing limit

[Copy link]
Posted on 4/10/2018 10:36:02 PM | | | |


First of all, we have 100 unprocessed messages on our rabbitmq server, we open a consumer client at random, and the following situation will appear,

100 pieces of data, all pushed over in an instant, but we can't process so much data at the same time with a single client, what should we do?




As shown in the image above, we did not confirm the receipt of the message! If the producer continues to send it, we consumers will keep receiving it!

Just imagine, if, we single consumer can process up to 60 messages in 1 minute, however, a producer may send 300 messages in 1 minute, if,We have a consumer client that needs to receive 300 messages at the same time in 1 minute, which has exceeded our maximum load, which may lead to server resources being exhausted and the consumer client getting stuck
RabbitMQ provides a qoS (Quality of Service) feature, that is, under the premise of non-automatic confirmation of messages, if a certain number of messages (by setting the value of Qos based on consume or channel) are not confirmed, new messages will not be consumed.



prefetchSize:0
prefetchCount: Tells RabbitMQ not to push more than N messages to a consumer at the same time, i.e. once there are N messages that have not yet acked, the consumer will block until there is a message ack
global:true\false Whether the above settings are applied to channels, to put it simply, whether the above restrictions are at the channel level or at the consumer level
Note: It is said that prefetchSize and global are not implemented by rabbitmq, so I will not study them for the time being


prefetch_count takes effect when no_ask=falseThat is, in the case of auto-answering, these two values areNot in effectof

Set prefetchCount = 3 via the BasicQos method. This allows RabbitMQ to process up to 3 messages per consumer at the same time. In other words, it will not distribute new Messages to the consumer until it receives the ack. Here's how to set it up:





As you can see in the figure, there are two consumers listening to Queue at the same time, but note that the message here will only be automatically accked if it is consumed by one consumer, and the other consumer will not get this message again.

Official website introduction: http://www.rabbitmq.com/consumer-prefetch.html

Note that this method may cause the queue to be full. Of course, you may need to add more Consumers or create more virtualHosts to refine your design.





Previous:EF implements bulk database inserts, updates, and deletes
Next:The IIS Express web server could not be started
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com