rabbitmq报错:PRECONDITION_FAILED - parameters for queue ‘test-1‘ in vhost ‘/‘ not equivalent

 错误如下:

[root@master2 rabbitmq-python]# python send-1.py 
Traceback (most recent call last):
  File "send-1.py", line 9, in <module>
    channel.queue_declare(queue='test-1')
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 2507, in queue_declare
    self._flush_output(declare_ok_result.is_ready)
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1340, in _flush_output
    raise self._closing_reason  # pylint: disable=E0702
pika.exceptions.ChannelClosedByBroker: (406, "PRECONDITION_FAILED - parameters for queue 'test-1' in vhost '/' not equivalent")

我的send-1.py是这样的

#*-*coding:utf-8*-*
#!/usr/bin/env python
import pika

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

channel.queue_declare(queue='test-1')
# 特别注意:当未定义exchange时,routing_key需和queue的值保持一致
for i in range(10):
    channel.basic_publish(exchange='', routing_key='test-1', body='Hello World!RabbitMQ,lzb.')

print(" [x] Sent 'Hello World!'")
connection.close()

我提前在web端手动Add a new queue,并可持久化,但是send-1.py中声明队列的时候没有可持久化,就会报错

 解决办法就是在队列声明时,加上可持久化参数

channel.queue_declare(queue='test-1',durable=True)

OK。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值