Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to RabbitMQ server hosted remotely

I have installed and configured RabbitMQ on Ubuntu 16.04 server using reference. Since the default user that is guest is only allowed to connect locally by default, I added a new user with the administrator tag and set its permission so that it can access / virtual host. I enabled RabbitMQ management console. I am successfully able to login with the user I created. I am also able to connect with RabbitMQ when I am connecting to it via localhost using my created user. But when I am trying to connect with the RabbitMQ server through other servers using following code:

import pika
credentials = pika.PlainCredentials('new_user', 'new_pass')
parameters = pika.ConnectionParameters('<server's Public IP>', 5672,'/',credentials)
connection = pika.BlockingConnection(parameters)

It throws an error:

Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 339, in init self._process_io_for_connection_setup() File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup self._open_error_result.is_ready) File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 395, in _flush_output raise exceptions.ConnectionClosed() pika.exceptions.ConnectionClosed

The same code works fine when I run this code on server, on which RabbitMQ is installed and by replacing <server's Public IP> with 0.0.0.0.

Output of sudo netstat -nltp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      18021/beam
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      18110/epmd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1230/sshd
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      18021/beam
tcp6       0      0 :::5672                 :::*                    LISTEN      18021/beam
tcp6       0      0 :::4369                 :::*                    LISTEN      18110/epmd
tcp6       0      0 :::22                   :::*                    LISTEN      1230/sshd

What could be causing this error?

like image 662
Rohini Choudhary Avatar asked Oct 29 '22 13:10

Rohini Choudhary


1 Answers

this usually happens with a very low connection timeout. adjust your connection string to include a larger connection timeout, such as 30 or 60 seconds, and you should be good to go.

looks like pika uses this setting https://pika.readthedocs.io/en/latest/modules/parameters.html#pika.connection.ConnectionParameters.blocked_connection_timeout

like image 97
Derick Bailey Avatar answered Nov 09 '22 06:11

Derick Bailey