Run Multiple Django Apps With Celery On One Server With Rabbitmq VHosts29 Apr · by Tim Kamanin · 0 min read
Sometimes, we can have multiple Django apps, each running celery, on a single server. If celery workers use Rabbitmq as a broker, we need to isolate them so that each worker uses a separate rabbitmq instance.
Luckily, Rabbitmq has a concept of virtual hosts, so we can create a host per celery app and call it a day. Here's how to do this:
Create rabbitmq server vhost at first:
sudo rabbitmqctl add_vhost our_app_vhost
Add user / password pair
sudo rabbitmqctl add_user username password
Grant permissions to our user on our vhost:
sudo rabbitmqctl set_permissions -p our_app_vhost username ".*" ".*" ".*"
If you want to give our user access to management backend execute this command:
sudo rabbitmqctl set_user_tags username management
Now you can add BROKER_URL to your Django app settings:
BROKER_URL = 'amqp://username:password@localhost:5672/our_app_vhost'
We have just created a virtual host for our Django app. Using this technique, create a virtual host for every Django/Celery app you have and enjoy the peace of mind.