rust-rdkafka
rust-rdkafka copied to clipboard
How to receive message or timeout
Hi,
I have subscribed to a topic. I would like to receive a message within the next 2 sec or else I want to timeout. I am unable to find a suitable method. Any example code will be helpful.
I see streamConsumer.recv() --> but this is blocking a call.
Hi, I faced the exact same issue some days ago and I came up with this solution:
let message = match tokio::time::timeout(timeout, consumer.recv()).await {
Ok(Ok(message)) => Ok(Some(message)),
Ok(Err(err)) => Err(err.to_string()),
Err(_) => Ok(None),
}?;
Ofc this needs tokio crate