[rabbitmq-discuss] Wrapping pika callbacks, why ?

Stephen Young stephen.t.young at gmail.com
Mon Aug 13 14:46:05 BST 2012


On Monday, August 6, 2012 10:29:00 AM UTC-4, Raphaël De Giusti wrote:
>
> Hi everyone,
>
> I'm interested in running pika's IOLoop in a thread and I came across this 
> code sample : 
> http://cms02.phys.ntu.edu.tw/tracs/env/browser/trunk/messaging/pika/mon.py
>
> I was wondering why and what could be the advantages of wrapping the 
> callbacks in methods (I can understand the on_exchange_declared() method 
> that returns a different callback according to thread's name) ?
>

 Advantages would be allowing the class to have direct access to the 
connection object, and being able to add custom functionality to the 
callbacks as needed - for example, passing custom headers when declaring 
exchanges and queues (if you want to use some of the other awesome RabbitMQ 
features like high availability, ttl, dead letter exchanges)
 

> Another question is why considering multiprocessing over threading in this 
> case ?
>

Multiprocessing is a way of getting around the GIL, which can make your 
application actually act in parallel. Threaded python cannot actually 
execute concurrent threads.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120813/8690b7ca/attachment.htm>


More information about the rabbitmq-discuss mailing list