examples icon indicating copy to clipboard operation
examples copied to clipboard

Add Example for Apache Kafka (rdkafka)

Open indrajitsinh opened this issue 5 years ago • 3 comments

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..)

indrajitsinh avatar Jan 03 '21 08:01 indrajitsinh

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.

fakeshadow avatar Jan 03 '21 08:01 fakeshadow

@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 https://github.com/actix/actix-web/issues/1283#issuecomment-629553449 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

indrajitsinh avatar Jan 03 '21 09:01 indrajitsinh

@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)

fakeshadow avatar Jan 03 '21 09:01 fakeshadow