简体   繁体   中英

pika sending messages to rabbitmq timeout

When trying to send a message from a laptop to another laptop with pika and rabbitmq I get this error. Any ideas how to solve this?

WARNING:pika.adapters.base_connection:Could not connect due to "timeout," retrying in 2 sec
ERROR:pika.adapters.base_connection:Could not connect: timeout
Traceback (most recent call last):
  File "C:/Users/Peter/Desktop/Blimp182-development(1)/Blimp182-development/Blimp182/send.py", line 7, in <module>
    connection = pika.BlockingConnection(parameters)
  File "C:\Python27\lib\site-packages\pika\adapters\base_connection.py", line 61, in __init__
    super(BaseConnection, self).__init__(parameters, on_open_callback)
  File "C:\Python27\lib\site-packages\pika\connection.py", line 513, in __init__
    self._connect()
  File "C:\Python27\lib\site-packages\pika\connection.py", line 804, in _connect
    self._adapter_connect()
  File "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", line 138, in _adapter_connect
    super(BlockingConnection, self)._adapter_connect()
  File "C:\Python27\lib\site-packages\pika\adapters\base_connection.py", line 120, in _adapter_connect
    self.params.retry_delay)
pika.exceptions.AMQPConnectionError: 2.0

Process finished with exit code 1

The used code is here:

import pika
import logging
logging.basicConfig()
credentials = pika.PlainCredentials('guest','guest')
parameters =    pika.ConnectionParameters('10.43.12.76', 55672, '/', credentials)
connection = pika.BlockingConnection(parameters=parameters)
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()

I'm not sure which version of RabbitMQ you are using but port 55672 was used for releases prior to 3.0. For newer releases 5672 is used. I know this question was asked a while ago, but 3.0 was released in 2012. This could have easily been the reason for your timeout issues.

1) The port number is incorrect (it should be 5672)

2) The "guest" user should not be for remote connection. If you want to use, it needs some additional configurations in the server. Refer : https://www.rabbitmq.com/access-control.html for configuration.

3) Ensure that the ports are not blocked. Open the below ports.

sudo iptables -I INPUT -p tcp --dport 5672 --syn -j ACCEPT

sudo iptables -I INPUT -p tcp --dport 5673 --syn -j ACCEPT

sudo iptables -I INPUT -p tcp --dport 15672 --syn -j ACCEPT

Thanks, Saravanan S.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM