我正在为一个消费者使用pika,该消费者使用来自say queue“email”的数据
当通过设置passive="True"
进行查询时,pika中的queue_declare
返回{
我使用web界面创建队列“email”,并且我可以看到它的存在(应该由第三方创建它;我这样做只是为了测试)。在
现在在我的程序中,当我打开频道并开始使用电子邮件队列之前,我想确保队列已经存在,所以我将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声明队列时没有指定回调吗?我只想知道queue是否存在,但是pika queue_declare
函数调用一个回调函数作为参数,并在没有给定回调函数时发出抱怨。在
您应该使用回调:
请检查文档中的示例:http://pika.readthedocs.org/en/latest/examples/asynchronous_consumer_example.html
相关问题 更多 >
编程相关推荐