Skip to content
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

Make using tokio as the executor easier #419

Open
huuff opened this issue Nov 6, 2024 · 1 comment
Open

Make using tokio as the executor easier #419

huuff opened this issue Nov 6, 2024 · 1 comment

Comments

@huuff
Copy link

huuff commented Nov 6, 2024

Today I needed to use a pretty non-standard configuration for lapin, and it was very hard to set up. I had difficulties setting up tokio as the executor and also using rustls with webpki root certs, but I think it's maybe better to focus on one issue at a time.

My biggest issue switching the runtime to tokio was requiring two other dependencies in the amqp-rs/ namespace (tokio-executor-trait and tokio-reactor-trait) and also ensuring they were in-sync with lapin itself.

I think that maybe lapin could offer a new tokio feature, that depends on these two (just like default-runtime does) and maybe also provide a ConnectionProperties constructor that automatically sets them up? Or maybe just using them in the Default implementation if the feature is enabled?

I may try this approach in a fork to simplify my downstream configuration. If it's ok by you, I could also work on a PR.

Thanks for your work on this project, by the way!

@huuff
Copy link
Author

huuff commented Nov 11, 2024

I've got a working PoC here https://github.com/huuff/lapin/tree/tokio-runtime

The entrypoint is:

#[cfg(not(feature = "tokio-runtime"))]
impl Default for ConnectionProperties {
    fn default() -> Self {
        Self {
            locale: "en_US".into(),
            client_properties: FieldTable::default(),
            executor: None,
            reactor: None,
            recovery_config: None,
        }
    }
}

#[cfg(feature = "tokio-runtime")]
impl Default for ConnectionProperties {
    fn default() -> Self {
        Self {
            locale: "en_US".into(),
            client_properties: FieldTable::default(),
            executor: Some(Arc::new(tokio_executor_trait::Tokio::current())),
            reactor: Some(Arc::new(tokio_reactor_trait::Tokio)),
            recovery_config: None,
        }
    }
}

When the tokio-runtume is enabled, the appropriate executor and reactor are passed-in by default, without requiring any set-up from the user. If this looks fine, I could roll a PR, but I'm also happy to make any necessary changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant