Queues
I attended the SpringOne 2GX conference in Chicago and had a great time. It’s always nice to learn a new thing or two. I wanted to take time to write down one of the things I learned about queues. Rob Harrop gave a great presentation on RabbitMQ which is an AMQP compliant queue.
Basic Message Flow
A. On the most basic level, Producers publish messages into an exchange with a specific key. For instance:
publish(exchange="main", key="sys.info" body="Hello world!")
B. Once the message is in the exchange, it somehow needs to make its way to a queue. Messages are routed to a queue based on a matching rule pattern. Queues are bound to exchanges using patterns.
queue.bind(exchange="main", routingKey="sys.*")
C. Consumers simply attach to a queue. What is interesting is if I have two consumers bound to a queue, messages that flow through the queue will be delivered only once in a round robin deliver. That means not all consumers will get all messages. The queue is a queue. Once a message is dequeued it’s gone.
If you do want to have multiple consumers receive the same message in a broadcast way, all yoou need to do is create two queues with the same routing rules.
In this case the message is routed to both Queue 1 and queue 2. For Queue 1, the two consumer will get the messages round robin.
Resources
- http://www.rabbitmq.com/tutorials/amqp-concepts.html