通过此处找到的 Rabbit MQ Pika HelloWorld 教程: https ://www.rabbitmq.com/tutorials/tutorial-one-python.html
问题是,每当我运行接收脚本时,我都会收到此错误:
Traceback (most recent call last):
File "receive.py", line 5, in <module>
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_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
这是我试图运行的代码:
#!/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()
任何帮助深表感谢。非常感谢你提前。
原文由 Colin Warn 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要做的就是在您的 PC 上安装 RabbitMQ。您可以在另一个终端中使用下面的命令简单地使用 docker 运行,然后重新运行您的代码