Multi Celery projects with same RabbitMQ broker backend process

杀马特。学长 韩版系。学妹 提交于 2019-12-18 11:34:17

问题


How can I use two different celery project which consumes messages from single RabbitMQ installation.

Generally, these scripts work fine if I use different rabbitmq for them. But on production machine, I need to share the same RabbitMQ backend for them.

Note: Due to some constraint, I cannot merge new projects in existing, so it will be two different project.


回答1:


RabbitMQ has the ability to create virtual message brokers called virtual hosts or vhosts. Each one is essentially a mini-RabbitMQ server with its own queues. This lets you safely use one RabbitMQ server for multiple applications.

rabbitmqctl add_vhost command creates a vhost.

By default Celery uses the / default vhost:

celery worker --broker=amqp://guest@localhost//

But you can use any custom vhost:

celery worker --broker=amqp://guest@localhost/myvhost

Examples:

rabbitmqctl add_vhost new_host
rabbitmqctl add_vhost /another_host

celery worker --broker=amqp://guest@localhost/new_host

celery worker --broker=amqp://guest@localhost//another_host



来源:https://stackoverflow.com/questions/12209652/multi-celery-projects-with-same-rabbitmq-broker-backend-process

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