Rabbitmq 出现 python 错误

Vla*_*lad 4 python rabbitmq mq

我已经安装了 pip install pika==0.11.0,如自述文件中所示,之后我尝试了 python receive.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'")
Run Code Online (Sandbox Code Playgroud)

即使我没有修改任何东西。我还尝试了 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()
Run Code Online (Sandbox Code Playgroud)

错误出现在以下行:

 channel.queue_declare(queue='hello')
Run Code Online (Sandbox Code Playgroud)

小智 5

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

channel.queue_declare(queue='hello', durable=True)
Run Code Online (Sandbox Code Playgroud)

请参阅教程的“消息持久性”部分。