更多详情参考官方文档:https://www.rabbitmq.com/tutorials/tutorial-six-python.html
参考博客:https://blog.csdn.net/weixin_41896508/article/details/80997828
01-HelloWorld(简单的消息队列)
send.py
import pika #与RabbitMQ服务器建立连接 credential = pika.PlainCredentials('yang','abc123456')#erase_on_connect是否清楚凭证 connection = pika.BlockingConnection(pika.ConnectionParameters('localhost',credentials=credential)) #创建频道 channel = connection.channel()#channel_number参数指定频道编号,建议默认pika自行管理 #创建频道传递消息的队列 channel.queue_declare(queue='hello') #向频道队列中发送消息 channel.basic_publish(exchange='', routing_key='hello', body='hello world!') print('[x]消息发送成功!') connection.close()#断开连接