Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IncompatibleProtocolError while trying to connect to RabbitMQ

I've got a problem with connecting from Python code using pika to dockerized RabbitMQ. I'm using this code to connect to the queue:

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=2)
def rabbit_connect():
    connection_uri = cfg.get("System", "rabbit_uri", raw=True)
    queue = cfg.get("System", "queue")
    username = cfg.get("System", "username")
    password = cfg.get("System", "password")
    host = cfg.get("System", "rabbit_host")
    port = cfg.get("System", "rabbit_port")
    credentials = pika.PlainCredentials(username, password)
    log.info("Connecting  queue %s at %s:%s", queue, host, port)
    connection = None
    try:
        connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))
    except Exception, e:
        log.error("Can't connect to RabbitMQ")
        log.error(e.message)
        raise

And these are my docker containers:

root@pc:~# docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                                                    NAMES
2063ad939823        rabbitmq:3-management   "/docker-entrypoint.s"   About an hour ago   Up About an hour    4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp   new-rabbitmg
94628f1fb33f        rabbitmq                "/docker-entrypoint.s"   About an hour ago   Up About an hour    4369/tcp, 5671-5672/tcp, 25672/tcp                                       new-rabbit

When I try to connect to localhost:8080 with any available credentials, pika retries connection until the error comes:

Traceback (most recent call last):
  File "script.py", line 146, in worker
    connection = rabbit_connect()
  File "build/bdist.linux-x86_64/egg/retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "build/bdist.linux-x86_64/egg/retrying.py", line 212, in call
    raise attempt.get()
  File "build/bdist.linux-x86_64/egg/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "build/bdist.linux-x86_64/egg/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "script.py", line 175, in rabbit_connect
    connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=credentials, host=host, port=int(port)))
  File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 339, in __init__
    self._process_io_for_connection_setup()
  File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup
    self._open_error_result.is_ready)
  File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 410, in _flush_output
    self._impl.ioloop.poll()
  File "build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py", line 602, in poll
    self._process_fd_events(fd_event_map, write_only)
  File "build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py", line 443, in _process_fd_events
    handler(fileno, events, write_only=write_only)
  File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 364, in _handle_events
    self._handle_read()
  File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 412, in _handle_read
    return self._handle_disconnect()
  File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 288, in _handle_disconnect
    self._adapter_disconnect()
  File "build/bdist.linux-x86_64/egg/pika/adapters/select_connection.py", line 95, in _adapter_disconnect
    super(SelectConnection, self)._adapter_disconnect()
  File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 154, in _adapter_disconnect
    self._check_state_on_disconnect()
  File "build/bdist.linux-x86_64/egg/pika/adapters/base_connection.py", line 169, in _check_state_on_disconnect
    raise exceptions.IncompatibleProtocolError
IncompatibleProtocolError

Is it some kind of bug? Or am I doing something not right?

like image 826
bartekmp Avatar asked Mar 03 '16 13:03

bartekmp


1 Answers

You have mapped localhost:8080 to docker container's (new-rabbitmg) port 15672, which is actually port for the webui management. The port for amqp communication is 5672 or 5671.

like image 120
cantSleepNow Avatar answered Oct 24 '22 11:10

cantSleepNow