【问题标题】:bad header response from rabbitmq when trying to make a connection尝试建立连接时来自rabbitmq的错误标头响应
【发布时间】:2021-05-05 13:18:44
【问题描述】:

我有两个容器正在运行以模拟一个代理和一个使用带有 poho 的 python 和使用 rabbitmq 作为代理的 sub。

当我尝试与 python 建立连接时,如下例所示。

import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("s/temp")

def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))


client = mqtt.Client(clean_session=True, userdata=None)
client.on_connect = on_connect
client.on_message = on_message

client.connect("rabbitmq", port=5672, keepalive=60, bind_address="")
client.loop_forever()

我从 rabbitmq 得到一个错误提示

rabbitmq  | 2021-05-05 02:57:43.478 [info] <0.1436.0> accepting AMQP connection <0.1436.0> (172.28.0.3:57387 -> 172.28.0.2:5672)
rabbitmq  | 2021-05-05 02:57:43.479 [error] <0.1436.0> closing AMQP connection <0.1436.0> (172.28.0.3:57387 -> 172.28.0.2:5672):
rabbitmq  | {bad_header,<<16,12,0,4,77,81,84,84>>}
rabbitmq  | 2021-05-05 02:57:43.481 [info] <0.1438.0> Closing all channels from connection '172.28.0.3:57387 -> 172.28.0.2:5672' because it has been closed

为了运行容器,我使用以下 docker-compose

services:
  rabbitmq:
    image: rabbitmq:latest
    container_name: "rabbitmq"
    ports:
      - 5672:5672
      - 15672:15672
    networks:
      - pubsub

  api:
    build: .
    container_name: "fastapi"
    ports:
      - 8000:80
    depends_on:
      - rabbitmq
    volumes:
      - .:/app
    networks:
      - pubsub

networks:
  pubsub:
    driver: bridge

我尝试在本地运行它,但我遇到了同样的错误,并且查看了一些博客和 see other stackoverflows 并没有找到答案

【问题讨论】:

    标签: python rabbitmq


    【解决方案1】:

    如果您使用 MQTT 协议进行连接,RabbitMQ:s 默认端口是 1883 和 8883(TLS)。也许这可能是问题所在?

    【讨论】:

    • 非常感谢您的帮助,我整天都在寻找它是什么,我通过运行命令 rabbitmq-plugins enable rabbitmq_mqtt 解决了它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 2015-01-26
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多