14 消息队列-rabbitMQ
消息队列-rabbitMQ
相关文档:
1 https://www.rabbitmq.com/tutorials/tutorial-one-python.html (官方文档)
2 http://rabbitmq.mr-ping.com/description.html (中文文档)
一 安装相关环境
参考博客:https://www.cnblogs.com/saryli/p/9729591.html
第一步:下载并安装erlang
第二步:下载并安装RabbitMQ
二 简单使用
#!\Users\Local\Programs\Python37 # -*- coding: utf-8 -*- import pika #1连接 connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() # 声明一个队列 channel.queue_declare(queue='hello') # 发送消息 channel.basic_publish(exchange='', routing_key='hello', body='Hello World2!') print(" [x] Sent 'Hello World2!'") #关闭连接 connection.close()
#!\Users\Local\Programs\Python37 # -*- coding: utf-8 -*- 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) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming()
使用参考:https://www.cnblogs.com/wupeiqi/articles/5132791.html
未完:待补充
作者:华王
博客:https://www.cnblogs.com/huahuawang/