hotPocket
hotPocket

Reputation: 69

RabbitMQ on Docker: Pika hangs on connection when given port, connection refused without port

I am trying to connect to a queue using pika, run on my local box, and rabbitmq run in a docker container. I am able to access rabbitmq on http://0.0.0.0:15677 with both curl commands and by viewing it in a web browser, so I know that rabbitmq looks like it is running fine - however, I cannot connect to it using python.

When I don't include the port in my pika.ConnectionParemeters, the connection is outright refused immediately. When I do include the port, the connection hangs and never shows on rabbitmq's side. Not sure if there's something funky going on with docker or with pika, but it is worth mentioning that my code connects to an otherwise identical rabbitmq server that is not a docker container.

I am running the newest version of OSX and using python 2.7 and pika 0.10.0.

RMQ_URL = '0.0.0.0'
HOST_QUEUE = 'snarfer'
VHOST = 'beta'
RMQ_PORT = 15677
ROUTING_KEY = 'snarfer.discovery'


self.connection = pika.BlockingConnection(pika.ConnectionParameters(
host=s.RMQ_URL, virtual_host=s.VHOST, port=s.RMQ_PORT))

***EDIT: Adding credentials to the ConnectionParameters does nothing.

Upvotes: 0

Views: 2074

Answers (1)

If you use the TCP port of the management web UI for your AMQP client, it cannot work: RabbitMQ expects HTTP requests on that port, not AMQP frames. That's why the client appears to hang.

If you don't specify a TCP port, it will use 5672, the default AMQP port. According to the management UI port (15677), I suppose your RabbitMQ is listening for AMQP connections on port 5677 because by default, the management plugin listens to $amqp_port + 10000.

Thus try with RMQ_PORT = 5677.

If it doesn't work, double-check your RabbitMQ configuration and/or look at the management UI to find out the AMQP port.

Upvotes: 1

Related Questions