【发布时间】:2014-05-24 09:33:00
【问题描述】:
我将 pika 用于消费队列“电子邮件”中的数据的消费者
queue_declare from pika 在通过设置passive="True" 进行查询时返回None,即使队列存在。
我使用网络界面创建队列“电子邮件”,我可以看到它存在(应该由第三方创建它;我这样做只是为了测试)。
现在在我的程序中,当我打开频道并开始在电子邮件队列上消费之前,我想确保队列已经存在,所以我将 passive 设置为 True:
def message(channel, envelope, properties, body):
if send(envelope.routing_key, body):
channel.basic_ack(envelope.delivery_tag)
return
print("Could not send message.")
def channel_open(channel):
QUEUES = CONFIG._defaults['queues']
queuelist = QUEUES.split(",")
for queuename in queuelist:
result = channel.queue_declare(message,queue=queuename, passive=True)
if not result:
raise NameError("declare the queues specified "
"in default config section first")
channel.basic_consume(queue=queuename, consumer_callback=message)
我得到的结果是“None”,而我期待得到一个“ok”,因为队列已经存在。任何指针???是因为使用 Web UI 声明队列时未指定回调吗?我只想知道队列是否存在,但 pika queue_declare 函数调用回调函数作为参数,并在没有给出回调函数时抱怨。
【问题讨论】:
-
我尝试了另一种方法(获取方法框架名称)来验证队列是否存在..但我也从 basic_get 得到 None method_frame, header_frame, body = channel.basic_get(message,queuename) if method_frame.NAME == 'Basic.GetEmpty':
-
顺便说一句,这是一个异步消费者
标签: python rabbitmq message-queue pika