Search code examples
pythonrabbitmqceleryamqp

Send message to specific consumer in celery (via routing key)


Does Celery support to specifically send a message to a specific consumer/client, e.g. via a routing key?

By default RabbitMQ a machine can targeted by using a direct queue, but I am trying to achieve the same behaviour with Celery

@app.task
def add(x, y):
    return x + y


# something like this
add.delay(1, 2, "machine-xyz")

Solution

  • You could run your worker-xyz as -Q worker-abc-queue to make it listen to a specific queue and then specify this queue name when you are calling the task to route it

    add.apply_async((1, 2), {}, queue='worker-abc-queue')