[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
Rabbitmq提供的交换机类型有fanout、direct、topic、headers四种。在AMQP协议中还提到另外两种类型:System和自定义
,本次文章主要介绍一下常用的交换机的特性。
1.fanout
该类型的交换机会将一条消息广播到绑定到该交换机的所有队列上,不论你设置的路由键是什么。
2.direct
该类型的交换机会将绑定的路由键完全匹配的方式路由到指定的队列上。如果路由键不匹配,那么就不会发送到任何队列中去。
3.topic
该种类型的交换机会是对上述fanout和direct类型的交换机的一种扩展。其和direct很类似,但是匹配规则上有所不同。其约定的路由匹配规则有:
routingkey通过符号“.”进行分割,其分割出来的单词就是路由的匹配元素。比如com.aa.tian这种就表示顺序单词com、aa、tian。
符号“*”和“#”分别用来进行模糊匹配,其中“*”用来表示一个单词,“#”用来匹配多个单词。
总结一下就是符号“*”表征一个单词,“#”表征多个单词。
4.headers
该类型的交换器不依赖路由键的匹配规则分发消息,而是根据发送的消息内容的headers属性进行匹配。在绑定队列和交换器时制定一组键值对,当发送消息到交换机的时候,rabbitmq会获取该消息的headers,对比其中的键值对是否完全匹配队列和交换器绑定时指定的键值对。如果完全匹配消息就会路由到该队列,否则不会路由到该队列。headers类型的交换机性能会很差,而且也不实用!
参考文献:《RabbitMq实战指南》- 朱忠华