我找到了解决方案。它很容易使用:))
设置" -n mynode @%h"什么时候开始芹菜 并设置目标选项,如add_consumer (queue = myqueue,destination = [' mynode @ hostname'])。
感谢。
=========================================
我用烧瓶,芹菜,兔子。
我想根据具有相同rabbitmq的消息来划分服务器A和B.
0. workers are always running on two servers(A, B) with this options.
celery -A myapp.mycelery worker -E --logfile=celery.log --pidfile=celery.pid
1. Make queue dynamically with CELERY_CREATE_MISSING_QUEUES=True option.
2. add consumer to run of newly maked queue.
mycelery.control.add_consumer(new_queue_name, reply=False)
3. Server A, B have 8 workers each. (total 16 workers)
4. add messages.
my_task.apply_async((params), queue=new_queue_name)
5. 16 workers process my_task messages concurrently very well.
但我想根据具有相同rabbitmq的消息来划分服务器A和B.
For example 1)
my_task_A.apply_async() -> run on server A only.
my_task_B.apply_async() -> run on server B only.
For example 2)
my_task.apply_async(queue=new_queue_name_startswith_A) -> run on server A only.
my_task.apply_async(queue=new_queue_name_startswith_B) -> run on server B only.
我动态制作的队列是直接交换。 (一条消息必须在一个队列中) 我无法增加rabbitmq服务器的数量。
请让我知道好的方法。或者我需要学习什么学期?