设置队列中的最大消息数

2024-04-18 03:50:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否可以设置队列中的最大消息数

假设我希望队列Foo中的msg不超过100个,可以这样做吗


Tags: 消息foo队列msg
2条回答

像这样做吧,开心点

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}
)

在这里的参数中您还需要跟踪队列的队列溢出行为

是的,这是可能的

official documentation

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.

好了,pika的channel.queue_declare有queue\u declare有arguments参数,这绝对是您想要的

相关问题 更多 >