Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 8. AMQP/RabbitMQ > Subscribing to a Message Queue

Subscribing to a Message Queue

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.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint