Search code examples
queuerabbitmqcatch-all

Rabbitmq and catch all queue


In my company I'm running a battery of tests running on different android devices.

Today tests (that are tasks) are running in a single queue with multiple workers.

I want to split this single queue in multiple queue, one for every device in order to optimize tests launches according to how many X devices my company has (i.e. if my company has 2 A devices I want to send tests on devices A in a queue with a single worker with --concurrency=2 so that I can launch max two test in a row).

I don't want migrate all in a time so I'm taking a first step to implement an hybrid version and logic I'd like to implement is the following.

Device A (there are two of them) and B (it's only one) go on queue A and queue B while all the others in the old legacy one.

enter image description here

My problem is with legacy queue. If I send a test on a device C, what I do is sending the task to queue C, since the catch_all queue is named legacy the task is not received. I'm searching a way to say: "please Rabbitmq use queue legacy if an existing queue name does not match with the device name".

There is a way to achieve this?


Solution

  • you can do this with a combination of Alternate Exchange (https://www.rabbitmq.com/ae.html), and bindings with routing keys

    Your setup would have QueueA and QueueB bound through your exchange, using a binding key that represents the device.

    | exchange| binding  | queue  |
    |---------|----------|--------|
    |  my.ex  | device.a | QueueA |
    |  my.ex  | device.b | QueueB |
    

    when you publish a message from Device A, it would have a routing key of device.a and would go to QueueA.

    Now for all of the legacy devices, you would set up an alternate exchange on the exchange configuration. This would deliver messages that don't match device.a or device.b routing keys, to the alternate exchange.

    The alternate exchange would then route all messages to the legacy queue.