【问题标题】:Rabbitmq with python error带有python错误的Rabbitmq
【发布时间】:2018-04-13 12:53:38
【问题描述】:

我已经安装了 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 填充:

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

【问题讨论】:

  • 如果您不显示代码,我们如何帮助您?

标签: python rabbitmq mq


【解决方案1】:

默认 vhost / 中的队列 @9​​87654322@ 已经存在,但它被声明为持久的。在执行代码之前删除此队列或从 Python 将其声明为持久:

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

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

【讨论】:

    【解决方案2】:
    # This script will publish MQ message to my_exchange MQ exchange
    
    import pika
    #credentials = pika.PlainCredentials('the_user', 'the_pass')
    #connection = #pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials('guest', 'guest')))
    connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, 'test', pika.PlainCredentials('admin', 'password1243')))
    channel = connection.channel()
    
    #channel.queue_declare(queue='items-queue', durable=Ture)
    channel.queue_declare(queue='dx-naas', durable=True)
    
    
    channel.basic_publish(exchange='my-exchange', routing_key='my-routing-key', body='Hello World!')
    
    print("[x] Sent 'Hello World!'")
    
    connection.close()
    
    

    【讨论】:

      猜你喜欢
      • 2017-01-01
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      相关资源
      最近更新 更多