当前位置:网站首页>rabbmitMQ 发布关键字模式<三>
rabbmitMQ 发布关键字模式<三>
2022-06-22 03:12:00 【风华浪浪】
生产者
import pika
import pika
# 输入普通凭据(登录用户名和密码)
credentials = pika.PlainCredentials('admin', 'admin')
# 输入连接参数(阻塞连接)
connection = pika.BlockingConnection(
pika.ConnectionParameters('106.13.168.8', credentials=credentials)
)
# 建立rabbit协议链接的通道
channel = connection.channel()
# 声明一个名为logs的fanout类型的交换机
channel.exchange_declare(exchange='logs2', exchange_type='direct') #发送参数 direct
# 发送消息内容
channel.basic_publish(
exchange='logs2',
routing_key='hello',
body='hello world'
)
print('[x] sent hello world')
connection.close()
消费者
import pika
# 输入普通凭据(登录用户名和密码)
credentials = pika.PlainCredentials('admin', 'admin')
# 输入连接参数(阻塞连接)
connection = pika.BlockingConnection(
pika.ConnectionParameters('106.13.168.8', credentials=credentials)
)
# 建立rabbit协议链接的通道
channel = connection.channel()
# 声明一个名为logs的direct类型的交换机
channel.exchange_declare(exchange='logs2', exchange_type='direct')#指定发送类型
# 绑定队列
channel.queue_declare(queue='queue_name', exclusive=True)
# 将队列绑定到交换机上
channel.queue_bind(exchange='logs2', queue='queue_name', routing_key='hello')
def callback(ch, method, properties, body):
print(" [x] %r" % body)
# 声明一个名为logs的direct类型的交换机channel.start_consuming()
channel.basic_consume(queue='queue_name', auto_ack=True, on_message_callback=callback)
channel.start_consuming()
边栏推荐
- 关于mysql的int型主键自增问题
- 【NVMe2.0b 12】NVM 容量模型
- 【 thesis 】 zero reference depth curve estimation for low light image enhancement
- Are you a technology manager or a project manager?
- NXP imx8mp learning records
- Redis configuration and optimization
- Sword finger offer 56 Delete duplicate nodes of the linked list
- TX2挂载SD卡,jtop
- 微信小程序onPageScroll无效
- 【爬虫笔记1】环境搭建和必要工具Selenium
猜你喜欢

TX2挂载SD卡,jtop

【爬虫笔记1】环境搭建和必要工具Selenium
![[nvme2.0b 8] nvme queue arbitration mechanism](/img/35/c5098623c14749711b205ef97c34a7.png)
[nvme2.0b 8] nvme queue arbitration mechanism

Check information on the Internet after the college entrance examination, and pay attention to prevent websites without SSL certificates

Installing and using mysql8 under Linux (Reprint)

powerdesigner CDM中联系理解

Redis6.0新特性(下)

A solution to memory leak in server

Vs loading symbols causes program to start slowly

不规范的命名
随机推荐
unity3D C# 在区间内生成不重复的随机数
策略模式
为什么在高并发下很容易就被setInterval给坑了
Use the serialize common command
调度功能:splunk-operator-controller-manager
Project management software development project management
golang标准库time
Fastdfs5.0.11 installation
Factory mode
uv_loop_init()流程
selenium入门级项目 - 豆豆玩竞猜
FastDFS-6.0.6
Implementation of epoll+threadpool high concurrency network IO model
Database interview summary
AtCoder Regular Contest 142
Figure database ongdb release v-1.0.2
Force buckle 102 Sequence traversal of binary tree
Policy mode
torch.max()使用讲解
图数据平台解决方案:单节点部署