kafka consumer polling timeout

john :

I am working with Kafka and trying to consume data from it. From the below line, I can poll the data from Kafka.

  while (true) {
    ConsumerRecords<byte[], <byte[]> records = consumer.poll(Long.MAX_VALUE);
    for (ConsumerRecord<byte[], <byte[]> record : records) {
        // retrieve data
    }
  }

My question is what is the benefit I am getting by providing Long.MAX_VALUE as the timeout as compared to if I provide 200 as the timeout. What is the best practice for the system that will be running production.

Can anyone explain me the difference of high timeout vs low timeout and which should be use in production system?

amethystic :

Setting MAX_VALUE is sort of a synchronous message consuming, waiting forever until we got something returned back from the poll, while setting to a lower value gives you a chance that you can decide to do something else other than awaiting. Which should be used depends on your actual scenario.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=453416&siteId=1