RabbitMQ

RabbitMQ是开源消息队列服务器,实现了AMQP协议。提供了集群等特性。
官方文档:
https://www.rabbitmq.com/getstarted.html
RabbitMQ包含四个主要部分:
Publisher消息发布者
Exchange交换机 将消息发给队列
Queue队列
Consumer消息接受者
python 客户端pika安装:

pip install pika

例子

1.一对一简单实现:

send.py:

#!/usr/bin/python
#-*- coding: utf-8 -*-
import pika

#If we wanted to connect to a broker on a different machine we'd simply specify its name or IP address here.
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
#创建连接
channel = connection.channel()

#create a company queue to which the message will be delivered:
channel.queue_declare(queue='company')

channel.basic_publish(exchange='',#交换机种类
                      routing_key='company',
                      body='holiday news')
print('holiday news')
connection.close()

receive.py:

#!/usr/bin/python
#-*- coding: utf-8 -*-
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
               'localhost'))
channel = connection.channel()

#申明队列,没有就创建
channel.queue_declare(queue=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值