gpt4 book ai didi

python - 带有python错误的Rabbitmq

转载 作者:行者123 更新时间:2023-12-05 03:06:10 27 4
gpt4 key购买 nike

我已经安装了 pip install pika==0.11.0,如自述文件所示,然后我尝试了 python receiver.py,它给了我以下错误:

Traceback (most recent call last):
File "receive.py", line 9, in <module>
channel.queue_declare(queue='hello')
File "C:\Python36\lib\site-packages\pika\adapters\blocking_connection.py", line 2400, in queue_declare
self._flush_output(declare_ok_result.is_ready)
File "C:\Python36\lib\site-packages\pika\adapters\blocking_connection.py", line 1258, in _flush_output
raise exceptions.ChannelClosed(method.reply_code, method.reply_text)
pika.exceptions.ChannelClosed: (406, "PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in vhost '/': received 'false' but current is 'true'")

即使我没有修改任何东西。我还尝试了 spring-amqp 示例,这些都有效。您能否提示我应该更改哪些内容?

这些是 py fille:

import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()


channel.queue_declare(queue='hello')

def callback(ch, method, properties, body):
print(" [x] Received %r" % body)

channel.basic_consume(callback,
queue='hello',
no_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

错误在以下行:

 channel.queue_declare(queue='hello')

最佳答案

默认虚拟主机 / 中的队列 hello 已经存在,但它被声明为持久的。在执行代码之前删除此队列,或在 Python 中将其声明为持久队列:

channel.queue_declare(queue='hello', durable=True)

请参阅 the tutorial 的“消息持久性”部分.

关于python - 带有python错误的Rabbitmq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49817518/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com