更多详情参考官方文档:https://www.rabbitmq.com/tutorials/tutorial-six-python.html

参考博客:https://blog.csdn.net/weixin_41896508/article/details/80997828

 微服务通信RPC

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()#断开连接
send.py

相关文章:

  • 2022-12-23
  • 2021-09-18
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-01-18
  • 2021-12-16
猜你喜欢
  • 2021-09-18
  • 2021-10-15
  • 2022-02-14
  • 2021-05-15
  • 2022-03-10
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案