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

Add Example for Apache Kafka (rdkafka) #397

Open
indrajitsinh opened this issue Jan 3, 2021 · 3 comments
Open

Add Example for Apache Kafka (rdkafka) #397

indrajitsinh opened this issue Jan 3, 2021 · 3 comments
Labels
good first issue Good for newcomers new-example Request for a new example

Comments

@indrajitsinh
Copy link

Thank you very much for this amazing library :)

I tried a lot of places but can't find a single working example of actix-web and Kafka ( i mostly interested in https://docs.rs/rdkafka/0.24.0/rdkafka/producer/future_producer/struct.FutureProducer.html so heavy tasks can be delegated to individual consumers like Sending an email or generating thumbnail etc..)

@fakeshadow
Copy link
Contributor

I've never used it but according to this phrase "This producer has an internal polling thread and as such it doesn't need to be polled. It can be cheaply cloned to get a reference to the same underlying producer. The internal polling thread will be terminated when the FutureProducer goes out of scope."

You can construct the producer at the start of your app and clone the producer and pass it to actix-web as App::data or App::app_data. Then you would have access to it in middleware and handler functions.

@indrajitsinh
Copy link
Author

indrajitsinh commented Jan 3, 2021

@fakeshadow Thanks for the quick replay

Yes I am trying to something like that but FutureProducer required tokio runtime and currently, I am using actix_rt, I have tried actix/actix-web#1283 (comment) that solution, but then I am getting tokio issue like actix-web internally using a different version then that snippet so it's not compiling

I am not that much experienced with actix-web or rust

@fakeshadow
Copy link
Contributor

@fakeshadow Thanks for the quick replay

but then I am getting tokio issue like actix-web internally using a different version then that snippet so it's not compiling

actix-web uses tokio runtime. You can run any crates support tokio directly as long as it uses the same version of tokio as actix-web.(which currently is 0.2 and it's compat with the latest release rdkafka on crates.io)

@robjtede robjtede added good first issue Good for newcomers new-example Request for a new example labels Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers new-example Request for a new example
Projects
None yet
Development

No branches or pull requests

3 participants