docker-compose with rabbitmq

1,652 views
Skip to first unread message

Noam

unread,
Feb 13, 2017, 5:49:30 AM2/13/17
to rabbitmq-users
Hi everyone,

I am trying to run a simple docker-compose file that will start rabbitmq in one container, and run another container with an app that connects to the rabbitmq container.

The YML file: 

version: '2'


services:

rabbitmq:

  image: rabbitmq:3.6.6-management

  hostname: my-rabbit

  ports:

    - "4369:4369"

    - "5671:5671"

    - "5672:5672"

    - "15672:15672"


app:

  image: my_app_image

  ports:

    - "8000:8000"


Something/s is/are missing here as when I run the docker compose YML file, connect to my app and run the rabbitmq's tutorial 'Hello World', I get a ConnectionClosed exception. Here's some more info:

I start the containers like this:

docker-compose up


connect to the app container:
docker-compose run app /bin/bash


Run the "Hello World" program below (based on the tutorial here):

import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(

      host='my-rabbit'))

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()



The exception I get:

Traceback (most recent call last):
  File "rmq.py", line 5, in <module>
    host='my-rabbit'))
  File "/home/eigenuser/env/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 339, in __init__
    self._process_io_for_connection_setup()
  File "/home/eigenuser/env/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup
    self._open_error_result.is_ready)
  File "/home/eigenuser/env/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 395, in _flush_output
    raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed


I looked around and could not find a simple example for this? 

Could anyone suggest an example or explain what is missing?

That would be much appreciated!

Noam

Michael Klishin

unread,
Feb 13, 2017, 5:51:35 AM2/13/17
to rabbitm...@googlegroups.com
Start by inspecting server logs.

User "guest" can only connect from localhost — that can be one reason:

The right thing to do is to create a new user and grant it full permissions (possibly
making it an administrator, if this is a development environment).

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Noam

unread,
Feb 13, 2017, 11:10:42 AM2/13/17
to rabbitmq-users
Thanks Michael,

Found my mistake: I used the hostname instead of the service name when defining the connection. 

For anyone interested, see below the correct way of connecting:

connection = pika.BlockingConnection(pika.ConnectionParameters(

      host='rabbitmq'))


Best wishes


Noam

Reply all
Reply to author
Forward
0 new messages