pika向rabbitmq超时发送消息

时间:2014-02-16 12:46:33

标签: python python-2.7 rabbitmq pika

当尝试使用pika和rabbitmq从笔记本电脑向另一台笔记本电脑发送消息时,我收到此错误消息。任何想法如何解决这个问题?

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

使用退出代码1完成处理

使用过的代码在这里:

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

2 个答案:

答案 0 :(得分:0)

我不确定您使用的是哪个版本的RabbitMQ,但是端口55672用于3.0之前的版本。对于较新的版本,使用5672。我知道这个问题刚才问过,但是在2012年发布了3.0。这可能很容易成为你超时问题的原因。

答案 1 :(得分:0)

1)端口号不正确(应该是5672)

2)“guest”用户不应该用于远程连接。如果要使用,则需要在服务器中进行一些其他配置。有关配置,请参阅:https://www.rabbitmq.com/access-control.html

3)确保端口未被阻止。打开以下端口。

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

谢谢, Saravanan S。