Search code examples
timerapache-kafkaresetdata-stream

Kafka Consumer - Reset Consumer Poll time


I have a Kafka Consumer with poll time mentioned like

kafkaConsumer.poll(polltimeinmilliseconds);

I would like to update the poll timer dynamically. Right now I set that to a static variable , and the poll time updates.

The problem is , the consumer waits for the old timer to complete. i.e if the old timer was 5 minutes, and if I update the timer to 10 ( dynamimcally ), it duly waits for the first 5 minutes before updating to 10 minutes interval.

How do I reset it immediately. i.e the timer should reset and set to 10 minutes immediately?


Solution

  • You can abort a long poll using the wakeup method.

    Wakeup the consumer. This method is thread-safe and is useful in particular to abort a long poll. The thread which is blocking in an operation will throw WakeupException. If no thread is blocking in a method which can throw WakeupException, the next call to such a method will raise it instead.