我正在尝试向 rabbitmq 发布一条消息。这在生产环境 env 中使用相同的代码就可以工作,所以我怀疑这是一个配置问题。
rbqueue = RabbitMQClientQueue('cn-dip-v3', host = rabbitmq_config['host'], username = rabbitmq_config['user'], password = rabbitmq_config['password'])
channel = rbqueue.connection.channel()
args = {"x-max-priority": 10}
channel.queue_declare(queue='cn-dip-v3', durable=True, arguments=args)
result = channel.queue_declare(exclusive=True)
callback_queue = result.method.queue
msgBody = json.dumps({"ohad":123})
# may happen that sendResponseToDal is True but there is no sendResponseToDal method on server side
data = {"body":msgBody,"queue_response" : False}
if responseHandler:
data["queue_response"] = True
corrID = str(uuid.uuid4())
channel.basic_publish(exchange='',routing_key='cn-dip-v3',properties=pika.BasicProperties(priority = 10, reply_to = callback_queue,correlation_id = corrID,),body=json.dumps(data))
有效queue_declare
。如果我删除它并运行同一行,队列就会被定义。我在管理面板中看到它,奇怪的是,在端口 55672 而不是 15672。
答案1
答案是,这是一个旧的安装。暂存区中是 2.8.4,生产区中是 3。
安装最新的 Rabbit 解决了这个问题。这是我使用的安装脚本:
vim install_latest_rabbit.sh
#!/bin/sh
cat <<EOF > /etc/apt/sources.list.d/rabbitmq.list
deb http://www.rabbitmq.com/debian/ testing main
EOF
curl https://www.rabbitmq.com/rabbitmq-signing-key-public.asc -o /tmp/rabbitmq-signing-key-public.asc
apt-key add /tmp/rabbitmq-signing-key-public.asc
rm /tmp/rabbitmq-signing-key-public.asc
apt-get -qy update
apt-get -qy install rabbitmq-server
sudo rabbitmqctl add_user guest guest
sudo rabbitmqctl set_user_tags guest administrator
sudo rabbitmqctl set_permissions -p / guest ".*" ".*" ".*"
sudo sh install_latest_rabbit.sh