Reputation: 423
How to can config rabbitmq queue for consume 20 messages per second? if i have multiple queues,is it possible to do that for each queue? such as:
q1-> 20 message per second
q2-> 15 message per second
Upvotes: 2
Views: 4650
Reputation: 1583
You can't configure queue in RabbitMQ to serve a limited amount of messages per second, you must do it programmatically.
A ugly technique is to use a single listener for that queue (that consumes a message at a time), and add a Thread.sleep(100L)
at the beginning of that method for 10 msg/s or a Thread.sleep(66L)
for 15msg/s (more generally, wait for 1000/nMesgPerSecond
). This guarantees more-or-less a lower bound on time spent by that method.
Upvotes: 0
Reputation: 174494
When using message-driven consumers, you would have to do the throttling in the listener itself - add Thread.sleep()
- or add an advice to the listener container's advice chain to separate the logic from your business code.
Generally, when wanting to control the rate of consumption, it might be easier to use a RabbitTemplate.receive()
operation (or RabbitTempalte.execute()
with channel.basicGet()
if you want to defer the acknowledgment until the message is processed).
Upvotes: 1