Running multiple instances of celery on the same server

僤鯓⒐⒋嵵緔 提交于 2019-12-04 05:55:51
munk

I solved this by using a virtual host for celery.

Once the rabbitmq server is running I issue these commands:

rabbitmqctl add_user user password
rabbitmqctl add_vhost app2
rabbitmqctl set_permissions -p app2 user ".*" ".*" ".*"

Then I start celery with:

celery -A tasks worker --broker=amqp://user:password@localhost/app2

With my task, I initialize the celery object like this:

celery = Celery('tasks', backend='amqp', broker='amqp://user:password@localhost:5672/app2

It looks like you're using AMQP so I would recommend solving this using different exchanges.

I recommend reading this blogposts about the AMQP structure: http://blogs.digitar.com/jjww/?s=rabbits&x=0&y=0

For Celery specific information, have a look here: http://docs.celeryproject.org/en/latest/userguide/routing.html

A short version of what you could do is give the apps a different default queue:

from kombu import Exchange, Queue

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