Search code examples
rabbitmqamqp

Are individual queues for clients a good approach to send messages only to them?


I have a system where clients pull tasks from a queue (via amqp, using RabbitMQ as a message server). When a new client gets spawned, he pulls a task, tells the main server that he is the one in charge for that specific task and starts executing the long-time task. From the server side I want to be able to cancel the task on this client so he can move on to another one in case the task already causes errors.

Pushing a cancel task on the existing task queue is no option because I have to guarantee it arrives in time or even at the same client.

When the client gets spawned, is it a good approach that the client sets up a dedicated exchange and queue only for him where the server can send commands to?


Solution

  • The client won't have to set up a dedicated exchange - you can use the default topic exchange or set up your own topic exchange.

    Then, when the client pulls a task it also creates its own exclusive queue and binds that queue to the topic exchange for a specific "cancel task X" routing key. Then, the client subscribes to this queue. If the task must be cancelled, the "server side" can publish a message to the topic exchange with the appropriate routing key.