Search code examples
servicerabbitmqmessage-queuesoaamqp

Message queues and application structure


I've read the documentation and I'm pretty sure I understand the concept of the different components present in an AMQP based message queue. However, I am having a hard time mapping that to an actual service oriented implementation. Could someone give a sort of "textbook" example of two services communicating through the pathway:

Producer -> Exchange -> Binding -> Queue -> Consumer

Specifically, I'm curious about when to reuse a queue or declare a new one. The "hello world" textbook naming conventions used in most systems for things like names of exchanges and such would be great as this has me quite flustered!


Solution

  • Queues are buckets of work that are waiting to be completed. If you only have 1 unit of work to be done, then you only need 1 queue.

    The reason to have more than 1 queue on an exchange is that you need to do different work on the same data. For example: lets say you get an incoming message and you want to:

    1. Write the data to a database
    2. Send an email

    You could accomplish this by creating a single FANOUT exchange with 2 queues. You then have 2 buckets of work that can be completed by two different consumers. The advantage of separating these is:

    1. Each queue can have N number of consumers
    2. Each queue has a smaller, more focused job

    There are lots more ways you could use rabbit. Hopefully this was helpful.

    Checkout the RabbitMQ getting started guide.

    http://www.rabbitmq.com/getstarted.html