I have two containers running to simulate a broker and a sub using python with poho, and using rabbitmq as a broker.
When I try to make a connection with python as in the following example.
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()
I get an error from rabbitmq saying
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
for running the containers I am using the following 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
I tried to run it locally but I got the same error, and see some blogs and see other stackoverflows and don't find the answear