Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selective routing with RabbitMQ

Tags:

rabbitmq

amqp

I have some queues bound to one topic exchange, e.g. with routing keys:

1) big.yellow.rabbit
2) small.*.dog
3) small.*.*
4) *.*.cat
5) *.*.*

I want the RabbitMQ to choose only one queue to place my message by following logic:

  • the number of coincident tags should be as big as possible
  • coincidence of first tag is more importat than for second...

Examples for aforementioned keys:

big.yellow.rabbit -> 1) 
small.yellow.rabbit -> 3) 
small.white.cat -> 3)
big.grey.cat -> 4)
big.yellow.pig -> 5)

I've come to conclusion that common exchange types (direct, topic, fanout, headers) will not help me. And I need to implement new custom type. Am I right?

Thanks.

like image 591
Igor Avatar asked Oct 30 '25 03:10

Igor


1 Answers

Yes, the routing logic you describe is not implemented by any of the default exchange types in RabbitMQ; you'll have to write your own.

You'll need to write a RabbitMQ plugin. More concretely, you'll need to write a custom exchange type: you can find a bunch of examples on the Developer Tools page.

If you need any pointers on how to get started or get stuck, post a question on the RabbitMQ-Discuss mailing list. The RabbitMQ developers read that list and make a point of not leaving any questions unanswered.

like image 179
scvalex Avatar answered Nov 01 '25 13:11

scvalex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!