19

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.

Ravi Kumar
  • 1,382
  • 16
  • 22

1 Answers1

30

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

Ajoy
  • 1,838
  • 3
  • 30
  • 57
mher
  • 10,508
  • 2
  • 35
  • 27
  • 2
    Worked great. Before implementing this method, I was trying with different Queue/Exchange config, but that didn't worked. With different VHOST, there is no conflict and both Celery apps are working fine to me. – Ravi Kumar Sep 04 '12 at 20:52