在RabbitMQ主题交换中路由与模式不匹配的消息

编程入门 行业动态 更新时间:2024-10-08 20:35:20
本文介绍了在RabbitMQ主题交换中路由与模式不匹配的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

两个队列通过以下路由键绑定到主题交换:

Two queues are bound to a topic exchange with the following routing keys:

队列A,绑定了路由键模式匹配*.foo 与路由键模式匹配*.bar

Queue A, bound with routing key pattern match *.foo Queue B, bound with routing key pattern match *.bar

我想在此交换中添加第三个队列,以接收既不是foo消息也不是bar消息的消息.如果我用#路由密钥将此队列绑定,我自然会得到我需要的所有消息,但包括不需要的foo和bar.

I'd like to add a third queue to this exchange that receives messages that are neither foo messages nor bar messages. If I bind this queue with a # routing key, I naturally get all messages I need, but including foo's and bar's which I don't want.

任何路由修补模式NOT *.foo和NOT *.bar的消息的方式?

Any way to route messages patching a pattern NOT *.foo AND NOT *.bar ?

推荐答案

如果要捕获所有与任何绑定都不匹配的消息,可以使用备用交易所.

If you want to catch all messages that doesn't match any bindings, that can be done with Alternate Exchange.

为现有交换添加交换,并从该交换收集所有消息:

Add alternate exchange for existent one and collect all messages from that alternate exchanges:

standard workflow --> [main exchange (topic)] | --> via binding *.foo --> [foo queue] | --> via binding *.bar --> [bar queue] v [alternate exchange (let it be topic too)] --> via binding * --> []

对于更具体的情况,当您具有N个绑定,但您想捕获所有不匹配M个绑定的消息(其中M< N)时,问题就更大了,但是从技术上讲,可以通过死信交换,然后将其发布到只有M个绑定的自定义交换,然后再用Alternate Exchange进行案例处理.但这听起来似乎很生锈,甚至没有考虑性能下降(仅在消息流非常大的情况下才适用).

For more specific cases when you have N bindings but you want to catch all messages that doesn't match M bindings (where M < N) it is more problematic, but technically can be done via Dead Letter Exchange and then publish it to custom exchange where you have only M bindings, and then apply case with Alternate Exchange. But it even sounds rusty, not even think about performance degradation (applied only if you have really high messages flow).

更多推荐

在RabbitMQ主题交换中路由与模式不匹配的消息

本文发布于:2023-11-25 10:18:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   不匹配   消息   模式   主题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!