Celery dynamic queue creation and routing

最后都变了- 提交于 2019-12-04 03:36:52

When you do the following:

task.apply_async(queue='foo', routing_key='foobar')

Then Celery will take default values from the 'foo' queue in CELERY_QUEUES, or if it does not exist then automatically create it using (queue=foo, exchange=foo, routing_key=foo)

So if 'foo' does not exist in CELERY_QUEUES you will end up with:

queues['foo'] = Queue('foo', exchange=Exchange('foo'), routing_key='foo')

The producer will then declare that queue, but since you override the routing_key, actually send the message using routing_key = 'foobar'

This may seem strange but the behavior is actually useful for topic exchanges, where you publish to different topics.

It's harder to do what you want though, you can create the queue yourself and declare it, but that won't work well with automatic message publish retries. It would be better if the queue argument to apply_async could support a custom kombu.Queue instead that will be both declared and used as the destination. Maybe you could open an issue for that at http://github.com/celery/celery/issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!