使用rpc

时间:2015-12-31 05:02:41

标签: python celery

我一直在尝试通过将结果持久化到队列来将Celery任务结果路由到另一个进程,而另一个进程可以从队列中选择结果。因此,已将Celery配置为CELERY_RESULT_BACKEND ='rpc',但仍未将Python函数返回值保持为队列。

不确定是否需要更改任何其他配置或代码。请帮忙。

以下是代码示例:

celery.py

from __future__ import absolute_import

from celery import Celery

app = Celery('proj',
         broker='amqp://',
         backend='rpc://',
         include=['proj.tasks'])

# Optional configuration, see the application user guide.
app.conf.update(
    CELERY_RESULT_BACKEND = 'rpc',
    CELERY_RESULT_PERSISTENT = True,
    CELERY_TASK_SERIALIZER = 'json',
    CELERY_RESULT_SERIALIZER = 'json'
)

if __name__ == '__main__':
    app.start()

tasks.py

from proj.celery import app

@app.task
def add(x, y):
    return x + y

运行芹菜
celery worker --app=proj -l info --pool=eventlet -c 4

1 个答案:

答案 0 :(得分:0)

通过使用Pika(AMQP 0-9-1协议的Python实现 - https://pika.readthedocs.org)解决将结果发布回celeryresults频道

相关问题