Routing messages in RabbitMQ topic exchange that do NOT match a pattern

二次信任 提交于 2019-12-10 18:17:20

问题


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

Queue A, bound with routing key pattern match *.foo
Queue B, bound with routing key pattern match *.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.

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


回答1:


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 * --> []

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).



来源:https://stackoverflow.com/questions/28351469/routing-messages-in-rabbitmq-topic-exchange-that-do-not-match-a-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!