How to run two grails apps on the same machine and have them not share a rabbitMQ

313 Views Asked by At

I have a grails app running with a single rabbit node. It is great. I want to fire up the same app a second time on the same machine on a different port. Currently, both apps answer jobs from both apps. I want their rabbits to be independent. What is the easiest way to ensure that each app only responds to the messages it sends? Multiple rabbit queues?

2

There are 2 best solutions below

0
On BEST ANSWER

You can provide a virtualhost entry in the grails configuration:

rabbitmq.connectionfactory.virtualHost  The name of the virtual host to connect to

Define two different vhosts in RabbitMQ, and each grails app will have their very own configured area to use. Messages sent through one vhost will only be available on that vhost, effectively separating the two grails apps without having to change queue setup or other internal parts of each app - just the configuration of the connection.

Remember that access control is performed on a per vhost basis, so you'll have to give your user access to each vhost in rabbitmq.

0
On

As @fiskfisk said, multiple vhosts is an option, and would work particularly well if you have a complex set of queues, exchanges, and bindings. There are some downsides to using a new vhost for the second application, including duplication of access control management, as well as some minor performance overhead.

If you have a fairly simple queue/exchange/binding setup, I would suggest pointing the second app at a queue with a different name, or giving your app the ability to be runtime-configured to either use a different queue, or to leverage the topic-based routing within RabbitMQ and have each app flag their messages with an app-specific prefix (or something similar).

One advantage of using topic routing to differentiate apps is that you can easily dip into the full stream of messages and do other things with that stream that you didn't foresee initially, including things like archival logging or audit logging, as well as other metrics collection or analysis.


tl;dr;

For long-term flexibility, have each instance of your application send messages to queues based on topic-routing.

For quick-and-dirty / get-it-working-yesterday, use a separate vhost for each instance of your application.