[英]Python Celery weird behavior when routing tasks to specific RabbitMQ queues
I was banging my head on this for a while and I still could not figure out what the issue is.我在这个问题上纠结了一段时间,但我仍然无法弄清楚问题是什么。 I am trying to route different tasks to their own specific queues.
我正在尝试将不同的任务路由到他们自己的特定队列。 In RabbitMQ, I have the default
celery
queue and another queue named test_queue
.在 RabbitMQ 中,我有默认的
celery
队列和另一个名为test_queue
的队列。 I can push tasks into the celery
just fine, but I am having trouble figuring out how to push tasks into the test_queue
queue.我可以将任务推入
celery
就好了,但我无法弄清楚如何将任务推入test_queue
队列。 I have read the documentation for the celery settings task_default_queue
, task_queue
, and task_routes
.我已阅读 celery 设置
task_default_queue
、 task_queue
和task_routes
的文档。
celery.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('celery_test',
broker_url='amqp://',
backend='amqp://',
include=['celery_test.tasks'],
worker_max_tasks_per_child=1,
task_create_missing_queues=True,
#task_queues = {'test_queue': {'exchange': 'test_queue', 'routing_key': 'test_queue'}},
#task_routes = {'celery_test.tasks.test': {'queue': 'test_queue'}}
#task_default_queue='test_queue'
)
# Optional configuration, see the application user guide.
app.conf.update(result_expires=3600,)
app.conf.task_routes = {'celery_test.tasks.test': {'queue': 'test_queue'}}
if __name__ == '__main__':
app.start()
I noticed that when I specify the test_queue
queue name in the Celery
constructor, my tasks do not get properly routed to the correct RabbitMQ queue.我注意到,当我在
Celery
构造函数中指定test_queue
队列名称时,我的任务没有正确路由到正确的 RabbitMQ 队列。 Instead, I had to use app.conf.task_routes = {'celery_test.tasks.test': {'queue': 'test_queue'}}
to get the job done.相反,我不得不使用
app.conf.task_routes = {'celery_test.tasks.test': {'queue': 'test_queue'}}
来完成工作。 I know this seems trivial but I have been beating my head on this for hours and I cannot figure out why one method works but not the other.我知道这似乎微不足道,但我已经为此苦苦挣扎了好几个小时,我无法弄清楚为什么一种方法有效而另一种方法无效。
Here is my celeryconfig.py这是我的 celeryconfig.py
broker_url="amqp://"
result_backend="amqp://"
include=["tasks"]
task_acks_late=True
task_default_rate_limit="150/m"
task_time_limit=300
worker_prefetch_multiplier=1
worker_max_tasks_per_child=2
task_routes={'tasks.test': {'queue': 'test_queue'}}
I am using我在用
As far as I know, the Celery 4.x (class) constructor does not take those parameters you mentioned (task_queues, task_routes and task_default_queue).据我所知,Celery 4.x(类)构造函数不采用您提到的那些参数(task_queues、task_routes 和 task_default_queue)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.