Here at LShift we’re often discussing RabbitMQ
. We’re keen about complicated deployment scenarios, redundancy of the broker and other complex use cases. While these problems are extremely interesting, some believe they are irrelevant for a great majority of RabbittMQ users.
People keep asking how to get started with Rabbit. There are some very good sources
however, understanding the AMQP abstractions requires some time.
Having that in mind I was astonished when I’ve seen this code
, where Brian wraps AMQP code
with a very simple Queue-like interface. This reminded me that messaging can be trivial and intuitive. In some environments, a queue is exactly what you need from messaging.
Let the Python snippet describe his interface:
>>> import amqp_wrapper
>>> q = amqp_wrapper.QueueProducer("test_queue")
Connected to test_queue (0 msgs, 0 consumers)
>>> q.write("hello world!")
>>> q = amqp_wrapper.QueueConsumer("test_queue")
('hello world!', 1)
>>> q.get() # never blocks
This code never blocks: if the queue is empty we receive a (None, None) tuple. This means that when the queue is empty we have to do polling, which never is a good choice.
>>> import amqpqueue
>>> qp = amqpqueue.Producer('testqueue')
>>> qc = amqpqueue.Consumer('testqueue')
>>> qc.get() # this blocks