mfontanini / cppkafka

Modern C++ Apache Kafka client library (wrapper for librdkafka)
BSD 2-Clause "Simplified" License
587 stars 207 forks source link

Detect network issue or no message scenario #271

Open rajdippatel-emc opened 3 years ago

rajdippatel-emc commented 3 years ago

Hello,

I want to know correct way to detect network issues while polling messages from consumer. I noticed that when network had issue consumer keeps returning null message. Also when there is no message on server side, it is returning null message too. So it is not possible whether it is network issue or no message. I have following code.

while (true) {
    Message msg = consumer.poll();

    if (!msg) {
        ** This condition is executed when there is no message or network has issues**
        continue;
    }

    if (msg.get_error()) {
        if (!msg.is_eof()) {
        }
        continue;
    }

    cout << "Received message" << msg.get_payload() << endl;
}
accelerated commented 3 years ago

You can get network errors via the error callback IIRC