两个队列通过以下路由键绑定到主题交换:
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主题交换中路由与模式不匹配的消息
发布评论