当 kafka max.poll.interval.ms
达到并发生重新平衡时,是否会在某处抛出异常?
最佳答案
一旦您的消费者因 poll()
过长而被踢出消费者组,您将收到 CommitFailedException
。根据documentation :
It is also possible that the consumer could encounter a "livelock" situation where it is continuing to send heartbeats, but no progress is being made. To prevent the consumer from holding onto its partitions indefinitely in this case, we provide a liveness detection mechanism using the
max.poll.interval.ms
setting. Basically if you don't call poll at least as frequently as the configured max interval, then the client will proactively leave the group so that another consumer can take over its partitions. When this happens, you may see an offset commit failure (as indicated by aCommitFailedException
thrown from a call tocommitSync()
). This is a safety mechanism which guarantees that only active members of the group are able to commit offsets. So to stay in the group, you must continue to call poll.
因此,您可能会捕获CommitFailedException
。实际上,您可以继续调用 poll()
直到重新平衡完成并且您的消费者重新进入消费者组。
关于java - 如何知道java kafka应用程序客户端中是否达到了max.poll.interval.ms?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61125555/