Throttling an AMQP Consumer Using RabbitMQ

I'm using AMQP in a reliability pattern and my use-case is to put messages in a queue, then consume them and insert the information into a web service. My web service is slow, and my queue can have many, many messages and I would like to ensure that the consumer doesn't kill my database.

Is there a build-in way to perform throttling in RabbitMQ, either time-based(only X messages per minute/second/hour) or some other mechanism?


There is per-connection flow control, so if you have too much messages on server, publishers will be awaiting. RabbitMQ is very reliable system, i can say that you can no worry about it.

If you are talking about how to limit consumption, probably you have to take care about it by yourself. You may also look on channel.flow (deprecated as of RabbitMQ 3.3.0) and basic.qos methods or you can even temporary disconnect consumer(s) and reconnect them back when your services will be capable to take the load.

UPD I can suggest that you consume messages with basic.consume and feed it to your web service. Based on how long does you web service process payload you may guess it's load and do some kind of sleep(N) . While your consumer be sleeping it will not consume anything so no web service will be fed.


I'm wondering if "Per-Connection Flow Control" is related with the channel.flow().

Basically you can call channel.flow(false); to inform the broker to stop sending messages.
Calling channel.flow(true); makes the flow active again. Here's the javadoc.

链接地址: http://www.djcxy.com/p/34070.html

上一篇: 如何从AMQP(RabbitMQ)队列中删除消息?

下一篇: 使用RabbitMQ限制AMQP使用者