创建 celery 多队列

Create celery multiple queues

我有一个包含类别列表的配置文件

cat_link = {'cat1':[link1,link2....],'cat2':[link3,link4....],'cat3':[link5,link6....],'cat4':[link7,link8....]}

我想根据配置文件中定义的类别总数创建队列,而且当我处理特定类别的链接时,每个队列都应该处理自己的一组链接。

处理链接的任务是一样的。我只想要每个类别链接都应在其特定队列中处理。

应该是这样的:-

for category, link in cat_link.iteritems():
    process_link.apply_async(args=[link],
                             queue=category,)

我应该如何创建动态队列,记住将来任何类别都可以 removed/added?

我的 celeryconfig 应该是什么样的?目前如下:-

BROKER_URL = 'amqp://'
CELERY_RESULT_BACKEND = 'amqp://'

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT=['json']
CELERY_TIMEZONE = 'Europe/Oslo'
CELERY_ENABLE_UTC = True

#Should I read my `cat_link` config setting in a loop and then create the queues??

我见过不同的任务有不同的队列,但是同一个任务有可能有不同的队列吗?

如果你想要动态的不同队列,

process_link.apply_async(args=[link1],
                         queue=queue1)

process_link.apply_async(args=[link2],
                         queue=queue2)

你还必须在配置文件中插入以下内容

CELERY_CREATE_MISSING_QUEUES = True

但是你必须关心的一件事是启动worker时,你必须传递-Q 'queue name'作为参数

前任

celery -A proj worker -l info -Q queue1,queue2

用于从该队列消费 'queuename'