【发布时间】:2018-01-30 14:09:40
【问题描述】:
我有来自 rabbitmq 文档中的示例用 Python 编写的 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++ 客户端:
#include <SimpleAmqpClient/SimpleAmqpClient.h>
using namespace AmqpClient;
int main(int argc, char *argv[])
{
Channel::ptr_t channel;
channel = Channel::Create("SERVER_HOST", SERVER_PORT,
"LOGIN", "PASS", "/");
BasicMessage::ptr_t msg = BasicMessage::Create("HELLO!!!");
channel->DeclareQueue("hound");
channel->BasicPublish("", "hound", msg, true);
}
但是当我发送消息时出现错误:
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 编写的发送方运行良好:
#!/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++ 客户端显示这个错误?
【问题讨论】: