# 多worker,多队列实例 # demo.py from celery import Celery app = Celery() app.config_from_object("celeryconfig") @app.task def taskA(x,y): return x + y @app.task def taskB(x,y,z): return x + y + z @app.task def add(x,y): return x + y # celeryconfig.py from kombu import Exchange,Queue BROKER_URL = "redis://192.168.48.131:6379/1" CELERY_RESULT_BACKEND = "redis://192.168.48.131:6379/2" CELERY_QUEUES = ( Queue("default",Exchange("default"),routing_key="default"), Queue("for_task_A",Exchange("for_task_A"),routing_key="for_task_A"), Queue("for_task_B",Exchange("for_task_B"),routing_key="for_task_B") ) CELERY_ROUTES = { 'demo.taskA':{"queue":"for_task_A","routing_key":"for_task_A"}, 'demo.taskB':{"queue":"for_task_B","routing_key":"for_task_B"} } # 启动一个worker来指定taskA # celery -A demo worker -l info -n workerA.%h -Q for_task_A # celery -A demo worker -l info -n workerB.%h -Q for_task_B # celery -A demo worker -l info -n workerB.%h -Q celery # 在客户端进行调用 from tasks import * re1 = taskA.delay(100, 200) print(re1.result) re2 = taskB.delay(1, 2, 3) print(re2.result) re3 = add.delay(2, 3) print(re3.status)
celery二
最新推荐文章于 2020-06-16 19:48:45 发布