-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sharing Channel
over async green threads
#415
Comments
Hello, Basically, my point here will be: i'll always encourage you to follow the official documentation. It's there for a reason. That being saidn I'm also well aware that this kind of specificities can be hard and/or counter intuitive. Especially when dealing with green threads and not OS threads. Everything possible has been put into place in lapin to make sharing a Channel across threads (even OS threads) safe. Well, as safe as possible anyways. WRT the connection and channel closing, you can see lapin::Connection and lapin::Channel like some kind of smart pointers, backed by std::sync::Arc. Basically, we'll automatically close them when the last ref is dropped (unless you already clsoed it before). Each Channel holds a ref to the Connection, so the Connection will get closed automatically only after all the Channels got closed themselves. |
Hi, thank you for your thorough answer :) To clarify:
This means the I have another question regarding best practices. I have been using the connection pool from deadpool in combination with lapin.
|
I have built a web-app using axum&tokio that creates a new green thread per request. I'm using lapin for RPC with RabbitMQ over a single channel which seems to work.
I've stumbled across the RabbitMQ documentation which discourages sharing Channels. Does this apply to
lapin::Channel
too and does this apply in an async context?Is it recomment to share the connection and create a new
lapin::Channel
per incoming request?Also it says in the documentation that closing a connection closes the underlying channels. Dropping a
lapin::Connection
doesn't close the underlyingConnection
which surprised me. Is it necessary to implement clean up code that closes alllapin::Connection
andlapin::Channels
at the end?The text was updated successfully, but these errors were encountered: