简体   繁体   中英

Determine what queue a celery task came from?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM