浏览此处的 Rabbit MQ Pika HelloWorld 教程:https://www.rabbitmq.com/tutorials/tutorial-one-python.html 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()
任何帮助深表感谢。预先非常感谢您。
您所需要做的就是在您的 PC 上安装 RabbitMQ。您可以简单地在另一个终端中使用以下命令运行 docker,然后重新运行您的代码
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)