交换机之Direct模式
2025-4-20
| 2025-4-20
Words 530Read Time 2 min
type
status
date
slug
summary
tags
category
icon
password
fonout 模式下,只要绑定到一个交换机上都可以接收到消息,可以实现广播模式,但是不能实现指定分发,而 Direct 模式下可以实现指定 routKet 的方式,让指定队列接收到消息。
创建流程是先创建交换机,再创建队列,然后把交换机和队列绑定,并且设置 routeKey。

消费者 1

队列名称 console
交换机 direct_logs
routeKey:info 和 warning,也就是说,当交换机向info 或者warning都会接收到消息。

消费者2

交换机和消费者 1 一样
不同的队列和routeKey

生产者

结果:

生产者发送消息的时候,指定交换机,并且指定不同的 routeKet 可以路由到不同的队列
指定 routeKey为error
notion image
notion image

指定routeKey 为 info

notion image
notion image

或者 warning

notion image
notion image
交换机之Topics模式交换机之-fanout-模式
Loading...