Im learning basics of RabbitMQ, installed it on a container. When inspecting the container it seems ok .
PS C:\Users\jvidin> docker port rabbitmq
25672/tcp -> 0.0.0.0:32776
4369/tcp -> 0.0.0.0:32779
5671/tcp -> 0.0.0.0:32778
5672/tcp -> 0.0.0.0:32777
PS C:\Users\jvidin> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2fe1297c403 rabbitmq:latest "docker-entrypoint..." 22 minutes ago Up 22 minutes 0.0.0.0:32779->4369/tcp, 0.0.0.0:32778->5671/tcp, 0.0.0.0:32777->5672/tcp, 0.0.0.0:32776->25672/tcp rabbitmq
55253e21bb49 b38ce49eadce "docker-entrypoint..." 8 weeks ago Up 3 hours 0.0.0.0:5433->5432/tcp mypostgres9.6
But than when trying to connect via Pika Python lib as below it fails with message below
pika.exceptions.ConnectionClosed: Connection to 127.0.0.1:5672 failed: timeout
Code
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
RESOLUTION BELOW CORRECT CONNECTION INFO
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', port=32777))
You need to configure your python client to use localhost:32777
.
Just check the output of docker port rabbitmq
. It shows that container port 5672
is mapped to port 32777
on your docker host.