在芹菜中广播消息 [英] Broadcast messages in celery

查看:82
本文介绍了在芹菜中广播消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用芹菜,想将广播任务发送给几个工人。我正在尝试按照 http://docs.celeryproject.org/en上的描述进行操作/latest/userguide/routing.html#broadcast ,因此我创建了一个简单的任务应用程序:

I'm using celery and want to send broadcast task to couple of workers. I'm trying to do it like is described on http://docs.celeryproject.org/en/latest/userguide/routing.html#broadcast so I create simple app with task:

@celery.task
def do_something(value):
    print value

在我制作的应用程序中:

and in app I made:

from kombu.common import Broadcast
CELERY_QUEUES = (Broadcast('broadcast_tasks'), )
CELERY_ROUTES = {'my_app.do_something': {'queue': 'broadcast_tasks'}}

我正尝试将任务发送给以下人员:

and then I was trying to send task to workers with:

my_app.do_something.apply_async(['222'], queue='broadcast_tasks')

或:

my_app.do_something.apply_async(['222'])

但很不幸在第一种方式中,任务一次只能正常发送给一个工人-因此,如果我有两个工人比任务要完成一次或第一次,第二次完成一次。第二种方式,我不知道该任务在哪里完成,因为在任何工人上都没有结果。
也许你们当中有人会知道为什么它不能像广播那样工作,而我在这里做错了什么。预先感谢您的帮助。

but unfortunatelly in first way task is send "normally" only to one worker in one time - so if I have two workers than task is done once or first and once on second worker. In second way I don't know where is done this task, because on any worker there is no result of it. Maybe someone of You will know why it is not working like broadcast and what I'm doing wrong here. Thanks in advance for help.

推荐答案

您使用的是哪个经纪人?

What broker are you using?

如果您使用的是Redis,则当前无法按照该线程中的说明进行操作:

if you're using Redis, currently it won't work as explained in this thread:

https://groups.google.com/forum/#!searchin/celery-users/broadcast/celery -users / s4v_0ndiLT8 / rJSME59TQ4YJ

我正在使用RabbitMQ,效果很好。

I'm using RabbitMQ and it works fine.

这篇关于在芹菜中广播消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆