从 RabbitMQ 主题交换的 * 绑定中排除一条路由

Excluding one route from a *-binding on a RabbitMQ topic exchange

给定一个 RabbitMQ topic 交换,例如x1 消费者队列绑定如下:

"source": "x1",
"vhost": "rabbit",
"destination": "queue1",
"destination_type": "queue",
"routing_key": "A.*",
"arguments": {}

我现在想将一些匹配 A.* 的消息路由到不同的队列。例如,A.a 应该转到 queue2,而所有其他 A.* 应该仍然落在 queue1queue2 的绑定将如下所示:

"source": "x1",
"vhost": "rabbit",
"destination": "queue2",
"destination_type": "queue",
"routing_key": "A.a",
"arguments": {}

queue1 的绑定应该如何排除 A.a 但保留其余部分?有可能吗?

据我所知,你不能通过说 "not this" 或类似的东西来真正制作路由密钥。

为了达到你想要的效果,你可以尝试一些变通方法:为 queue 2 消费者设置一个大的预取计数,并确保该消费者是第一个连接到代理的(因为循环调度)。您必须弄清楚将预取计数设置为什么。

当然,有很多原因导致这并不总是有效(如果消费者掉线,或者太慢等等......)

这不是 topic 所做的,所以如果您必须使用这种类型的交换,则不能从绑定中排除一条路由。

您可能会发现 rtopic exchange 有用:

The idea is to be able to specify routing patterns when publishing messages. With the default topic exchange patterns are only accepted when binding queues to exchanges.