Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to use Pika BlockingConnection in web app?

I'm a little bit confused about BlockingConnection and AsyncoreConnection. I want to send some messages to the RabbitMQ queue from a Django app. Is it ok to do that using a global BlockingConnection object?

Thank You.

like image 433
User Avatar asked Jul 30 '14 22:07

User


1 Answers

You need to have one BlockingConnection object per thread, as stated in the pika FAQ:

Pika does not have any notion of threading in the code. If you want to use Pika with threading, make sure you have a Pika connection per thread, created in that thread. It is not safe to share one Pika connection across threads.

So, the answer depends on how you're deploying Django. If you're using Django in a multi-threaded deployment, you can't use a global BlockingConnection; you need to create one per-thread. If you're not using multi-threading, you can use a global BlockingConnection object.

like image 137
dano Avatar answered Sep 21 '22 06:09

dano