Umutcan Önal
Umutcan Önal

Reputation: 111

Slowing Down Rabbit MQ Delivery Rate

I am using Rabbit MQ for my application. Sometimes I need to stop my consumers due to maintenance. So, there will be thousands of messages waiting on the queue. After I restart my consumers, the message delivery rate is high (500-600 messages per second). At that rate, one of my consumers cannot handle the messages and break down the server.

I will change consumer code in the future, but now I need an quick soluton.

So, is there a way to slow down the delivery rate? I tried basicQos method, but it did not work.

Note: I am using Java for consumers.

Upvotes: 4

Views: 2146

Answers (1)

Umutcan Önal
Umutcan Önal

Reputation: 111

channel.basicConsume(queueName, false, consumer);
channel.basicQos(50);

consumer.getChannel().basicAck(delivery.getEnvelope().getDeliveryTag(), false);

First two lines makes the auto acknowlegment false and set a delivery limit. The third line acknowlege the message after processsing the message is complete. This solves my problem. When auto acknowlegment is true, consumer gets messages from queue even if processing previous messages is not complete. This causes memory problems and server failure.

Upvotes: 5

Related Questions