Determine what queue a celery task came from?

Viewed 23

Let's say I'm inside a celery task. Is there a way to determine where the task originated from. Say the machine is listening to queueA, queueB, queueC, when a task comes in is there a way to determine if it came from queueB? Alternatively, is there a way to check which queues a machine is listening to from inside a task?

@task
def myfunc():
    # which queue did this current task originate from? Or what queue(s) is this machine connected to?
1 Answers

Something like the following should work:

@app.task(name="myapp.myfunc", bind=True)
def myfunc():
    # which queue did this current task originate from? Or what queue(s) is this machine connected to?
    task_queue = self.request.delivery_info['routing_key']

Where "app" is an instance of Celery.

Related