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.
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.
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.
BlockingConnection
. It doesn't make sense to use a SelectConnection
because you're not using an event loop in your application. Plus, since you're just using BlockingConnection
to publish messages (rather than to consume them), you shouldn't be blocking on RabbitMQ calls for very long. –
Willumsen © 2022 - 2024 — McMap. All rights reserved.
enable-threads = true
,process = 8
. Should I create connection every request? Is there a sense usingpika.SelectConnection
in a synchronous application? – Tyre