Celery 芹菜广播任务不工作
我试着做一个广播任务,但每次通话只有一个工作人员收到。你能帮帮我吗?(我正在使用rabbitmq和节点芹菜) 我还测试了以下配置,但不工作Celery 芹菜广播任务不工作,celery,node-celery,Celery,Node Celery,我试着做一个广播任务,但每次通话只有一个工作人员收到。你能帮帮我吗?(我正在使用rabbitmq和节点芹菜) 我还测试了以下配置,但不工作 celery.conf.update( CELERY_RESULT_BACKEND = "amqp", CELERY_RESULT_SERIALIZER='json', CELERY_QUEUES=( Queue('celery', Exchange('celery'), routing_key='celery'),
celery.conf.update(
CELERY_RESULT_BACKEND = "amqp",
CELERY_RESULT_SERIALIZER='json',
CELERY_QUEUES=(
Queue('celery', Exchange('celery'), routing_key='celery'),
Broadcast('broadcast'),
),
)
@celery.task(ignore_result=True, queue='broadcast',
options=dict(queue='broadcast'))
def sample_broadcast_task():
print "test"
编辑
在通过添加-Q广播更改运行worker的方式后,现在我面临以下错误:
PreconditionFailed: Exchange.declare: (406) PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'broadcast' in vhost '/': received 'direct' but current is 'fanout'
根据你的描述: 我曾尝试进行广播任务,但每次通话只有一名员工收到广播任务
您可能正在使用直接类型交换。尝试了许多方法后,我终于找到了解决方案。这是我的工作。 (芹菜3.1.24(Cipater)和蟒蛇2.7.12) WORKER-tasks.py:
from celery import Celery
import celery_config
from kombu.common import Broadcast, Queue, Exchange
app = Celery()
app.config_from_object(sysadmin_celery_config)
@app.task
def print_prout(x):
print x
return x
WORKER-celery_config.py:
# coding=utf-8
from kombu.common import Broadcast, Queue, Exchange
BROKER_URL = 'amqp://login:pass@172.17.0.1//'
CELERY_RESULT_BACKEND = 'redis://:login@172.17.0.1'
CELERY_TIMEZONE = 'Europe/Paris'
CELERY_ENABLE_UTC = True
CELERY_TASK_SERIALIZER = 'pickle'
CELERY_RESULT_SERIALIZER = 'pickle'
CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']
CELERY_DISABLE_RATE_LIMITS = True
CELERY_ALWAYS_EAGER = False
CELERY_QUEUES = (Broadcast('broadcast_tasks'), )
工人下水时:
celery -A celery_worker.tasks worker --loglevel=info --concurrency=1 -n worker_name_1
在客户端(我的另一个docker容器)
我的下一步是如何检索和显示所有工作人员返回的结果。“print result.get()”似乎只返回最后一个工作者的结果。
这似乎不明显()试试这个
from celery import Celery
from kombu.common import Broadcast
BROKER_URL = 'amqp://guest:guest@localhost:5672//'
class CeleryConf:
# List of modules to import when celery starts.
CELERY_ACCEPT_CONTENT = ['json']
CELERY_IMPORTS = ('main.tasks')
CELERY_QUEUES = (Broadcast('q1'),)
CELERY_ROUTES = {
'tasks.sampletask': {'queue': 'q1'}
}
celeryapp = Celery('celeryapp', broker=BROKER_URL)
celeryapp.config_from_object(CeleryConf())
@celeryapp.task
def sampletask(form):
print form
要发送消息,请执行以下操作:
d= sampletask.apply_async(['4c5b678350fc643'],serializer="json", queue='q1')
from celery import Celery
from kombu.common import Broadcast
BROKER_URL = 'amqp://guest:guest@localhost:5672//'
class CeleryConf:
# List of modules to import when celery starts.
CELERY_ACCEPT_CONTENT = ['json']
CELERY_IMPORTS = ('main.tasks')
CELERY_QUEUES = (Broadcast('q1'),)
CELERY_ROUTES = {
'tasks.sampletask': {'queue': 'q1'}
}
celeryapp = Celery('celeryapp', broker=BROKER_URL)
celeryapp.config_from_object(CeleryConf())
@celeryapp.task
def sampletask(form):
print form
d= sampletask.apply_async(['4c5b678350fc643'],serializer="json", queue='q1')