Program Running Pika Throwing AMQPConnectionError

时间:2019-04-17 00:09:44

标签: python rabbitmq pika

Going through the Rabbit MQ Pika HelloWorld tutorial found here: https://www.rabbitmq.com/tutorials/tutorial-one-python.html

The problem is, I keep getting this error whenever I run my receive script:

"Traceback (most recent call last): File "receive.py", line 5, in pika.ConnectionParameters(host='localhost'))

File "C:\Users\Colin Warn\PycharmProjects\untitled2\venv\lib\site-packages\pika\adapters\blocking_connection.py", line 360, in init self._impl = self._create_connection(parameters, _impl_class)

File "C:\Users\Colin Warn\PycharmProjects\untitled2\venv\lib\site-packages\pika\adapters\blocking_connection.py", line 451, in _create_connec tion

raise self._reap_last_connection_workflow_error(error)

pika.exceptions.AMQPConnectionError "

Here's the code I'm attempting to run:

#!/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(
    queue='hello', on_message_callback=callback, auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

Any help is much appreciated. Thank you so much in advance.

2 个答案:

答案 0 :(得分:1)

您必须在计算机中安装Rabbit,然后再安装Rabbit服务器,然后重新运行该脚本,请查看rabbitmq.com/download.html。

感谢朱利安·萨拉斯(Julian Salas)。

答案 1 :(得分:1)

在您的 PC 上安装 RabbitMQ 所需的一切,您可以在另一个终端中使用以下命令简单地使用 docker 运行,然后重新运行您的代码

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management