Which form of connection to use with pika

The SelectConnection is useful if your application architecture can benefit from an asynchronous design, e.g. doing something else while the RabbitMQ IO completes (e.g. switch to some other IO etc) . This type of connection uses callbacks to indicate when functions return. For example you can declare callbacks for

on_connected, on_channel_open, on_exchange_declared, on_queue_declared etc.

…to perform operations when these events are triggered.

The benefit is especially good if your RabbitMQ server (or connection to that server) is slow or overloaded.

BlockingConnection on the hand is just that – it blocks until the called function returns. so it will block the execution thread until connected or channel_open or exchange_declared or queue_declared return for example. That said, its often simpler to program this sort of serialized logic than the async SelectConnection logic. For simple apps with responsive RabbitMQ servers these also work OK IMO.

I suppose you’ve read the Pika documentation already http://pika.readthedocs.io/en/stable/intro.html, if not, then this is absolutely vital information before you use Pika!

Cheers!

Leave a Comment

tech