Broadcast messages in celery

寵の児 提交于 2019-12-07 04:54:43

问题


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')

or:

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.


回答1:


What broker are you using?

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

I'm using RabbitMQ and it works fine.



来源:https://stackoverflow.com/questions/18644511/broadcast-messages-in-celery

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