我用Python编写了RabbitMQ监听器,这些监听器来自RabbitMQ文档中的示例:
#!/usr/bin/env python
import time
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hound')
def callback(ch, method, properties, body):
print(" [x] Received %r" % (body,))
time.sleep(5)
print(" [x] Done")
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_consume(callback,
queue='hound',
)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
和C++客户端尝试发送消息:
^{pr2}$但当我发信息时,我收到了一个错误:
terminate called after throwing an instance of 'AmqpClient::PreconditionFailedException'
what(): channel error: 406: AMQP_QUEUE_DECLARE_METHOD caused: PRECONDITION_FAILED - parameters for queue 'hound' in vhost '/' not equivalent
Aborted
但是!当我删除行时:channel->DeclareQueue("hound");
成功发送。在
使用Python编写的Sender write运行良好:
#!/usr/bin/env python
import sys
import pika
credentials = pika.PlainCredentials(
username=username, password=password
)
connection = pika.BlockingConnection(
pika.ConnectionParameters(
host=host,
virtual_host=virtual_host,
credentials=credentials,
port=RABBIT_PORT
)
)
channel = connection.channel()
channel.queue_declare(queue='hound')
channel.basic_publish(exchange='',
routing_key='hound',
body='hello!')
print(" [x] Sent %r" % (message,))
怎么了?为什么c++客户端显示这个错误?在
此错误是由于您试图re-declare a queue with different parameters引起的。在
如文档所述,队列声明将是idempotent assertion-如果队列不存在,则创建它。如果它确实存在,但是有不同的参数,就会得到这个错误。在
您的
DeclareQueue("hound");
方法中发生了与channel.queue_declare(queue='hound')
不同的问题。由于我们没有相关的代码,因此不可能进一步解释,但我认为这些信息足以帮助您解决问题。在相关问题 更多 >
编程相关推荐