问题
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