【发布时间】:2018-03-20 21:10:52
【问题描述】:
我目前正在关注 rabbitmq 教程并遇到了问题。无论我多么接近本教程,我在尝试运行我的 send.py 和 receive.py 时都会收到此错误:
pika.exceptions.ConnectionClosed: Connection to 127.0.0.1:5672 failed: [Errno 61] Connection refused
这是 send.py:
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
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()
这是receive.py:
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
我终其一生都无法弄清楚我做错了什么。我看过这里的其他帖子提出了类似的问题,但仍然没有骰子。
【问题讨论】:
-
你用
/etc/init.d/rabbitmq-server status检查过服务器的状态 -
您的桌面上是否安装并运行了 RabbitMQ 服务器?