RabbitMQ Header Exchange using a "NOT" or "Didn't fit anyone else go here"

StackOverflow https://stackoverflow.com/questions/22995372

  •  01-07-2023
  •  | 
  •  

Вопрос

I've been learning RabbitMQ the last couple weeks. I'm trying to setup a desicision tree type routing using a "Header" Exchange. I know how to brach it out if it matches. But I want a "catch all" queue that's only sent to if the header didn't match anything else in the tree.

So

Exchange1 -> if header.value1 = "company1" then goto queue "company1"

 -> if header.value1 = "company2" then goto queue "company2"

 -> if header.value1 didn't match anyone else then goto queue "catch all"

I got the first two easily figured out. But I can't figure out how to do a "not" or "didn't find a match".

If just set up a "catch all" without any rules associated with it, then ALL messages are sent there, including the ones that do find matches under the other rules.

Это было полезно?

Решение

There is no NOT capabilities in the RabbitMQ bindings. However, RabbitMQ provides a feature to do what you are looking for which is called Alternate Exchange.

You need to set a policy in the exchange to send the message to an alternative exchange and you will need to bind another queue (for you would be "catch all"). This new exchange will just get the messages that couldn't be routed before so it can be created as fanout.

You can find more information here: Alternate Exchanges

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top