6

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 ?

4

1 回答 1

7

如果您想捕获与任何绑定不匹配的所有消息,可以使用Alternate Exchange来完成。

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

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 应用案例。但它甚至听起来生疏,甚至不考虑性能下降(仅在消息流非常高的情况下应用)。

于 2015-02-05T20:04:41.660 回答