Reputation: 35149
I'm wondering is it possible to set the max number of messages in the queue?
Let's say I want to have no more than 100 msgs in queue Foo, is it possible to do?
Upvotes: 5
Views: 6184
Reputation: 497
Do it like this and be happy!
import pika
QUEUE_SIZE = 5
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(
queue='ids_queue',
arguments={'x-max-length': QUEUE_SIZE}
)
Here in arguments you will also need to track queue overflow behaviour for your queue.
Upvotes: 1
Reputation: 12879
Yes, it is possible.
The maximum length of a queue can be limited to a set number of messages by supplying the x-max-length queue declaration argument with a non-negative integer value.
AFAIK, pika's channel.queue_declare
has queue_declare has arguments
argument which is definitely what you want.
Upvotes: 8