Kafka Consumer - 重置消费者轮询时间

Kafka Consumer - Reset Consumer Poll time

我有一个 Kafka 消费者,其中提到了轮询时间

kafkaConsumer.poll(polltimeinmilliseconds);

我想动态更新轮询计时器。现在我将其设置为静态变量,并且轮询时间会更新。

问题是,消费者等待旧计时器完成。即,如果旧计时器是 5 分钟,并且如果我将计时器更新为 10(动态),它会适当地等待前 5 分钟,然后再更新为 10 分钟间隔。

如何立即重置它。即计时器应该立即重置并设置为 10 分钟?

您可以使用 wakeup 方法中止长轮询。

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.