Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In all our earlier examples, we used the pop method to retrieve messages from our queues. Although this method is straightforward and easy to understand, it is not the most direct way of getting these messages. I wanted you to understand the mechanics of what happens in a queue. With that said, there is a much easier way of getting messages from a queue—the subscribe method.
The subscribe method is a method on the MQ::Queue class. When called, the subscribe method registers a callback with the queue, telling it to call the attached block whenever a message appears in the queue. Let’s look at an example.