1

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?

Mikey
  • 4,692
  • 10
  • 45
  • 73
  • Can you please make this question a little easier to understand? What app do you want to fire up a second time? RabbitMQ? or your app? Why? If you provide some more detail I am pretty sure I can help you, and if not someone else will. thanks – robthewolf Jul 17 '12 at 07:43
  • @robthewolf two of the same grails app running on the same machine. Right now its working, but when one does rabbitSend, either one could answer it. – Mikey Jul 18 '12 at 00:57
  • sounds like you are connecting to the same queues both times. You either want dynamic queues where each instance will dynamically create a queue that is unique. Or when you run each instance of your consumer take a parameter that has the name of the queue to connect to / create. – robthewolf Jul 19 '12 at 06:52
  • @robthewolf is that different from vhosts? Is that easily accomplished with grails rabbit plugin? – Mikey Jul 19 '12 at 18:59
  • I am not sure that the vhosts solution is what you are looking for here. I could be wrong, I am still unclear what you are trying to do. Vhosts are basically to create a second instance of RabbitMQ so that it runs like a whole new server. If you are trying to have to simultaneous running systems, each with a producer, RabbitMQ and a consumer. Then Vhosts is the way to go. If you want one producer and 2 consumers to consume the same messages then you need a fanout exchange and two queues each connected to by a different consumer. – robthewolf Jul 20 '12 at 07:16

2 Answers2

3

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.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
2

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.

cdeszaq
  • 30,869
  • 25
  • 117
  • 173