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

霸气de小男生 提交于 2020-01-06 23:49:53

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/22995372/rabbitmq-header-exchange-using-a-not-or-didnt-fit-anyone-else-go-here

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