[英]How to know if max.poll.interval.ms is reached in java kafka application client?
Is there an exception thrown somewhere when kafka max.poll.interval.ms
is reached and rebalance happens?当达到 kafka
max.poll.interval.ms
并发生重新平衡时,是否会在某处引发异常?
Once your consumer gets kicked out of the consumer group due to long poll()
, you will receive a CommitFailedException
.一旦你的消费者由于长
poll()
被踢出消费者组,你将收到一个CommitFailedException
。 According to the 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.为了防止消费者在这种情况下无限期地持有其分区,我们提供了一种使用
max.poll.interval.ms
设置的活动检测机制。 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.基本上,如果您没有像配置的最大间隔那样频繁地调用 poll,那么客户端将主动离开组,以便另一个消费者可以接管其分区。 When this happens, you may see an offset commit failure (as indicated by a
CommitFailedException
thrown from a call tocommitSync()
).发生这种情况时,您可能会看到偏移提交失败(如调用
commitSync()
时抛出的CommitFailedException
所示)。 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.
所以要留在群里,你必须继续调用poll。
Therefore, you could possibly catch CommitFailedException
.因此,您可能会捕获
CommitFailedException
。 Actually, you can keep calling poll()
until re-balancing is complete and your consumer re-enters the consumer group.实际上,您可以继续调用
poll()
直到重新平衡完成并且您的消费者重新进入消费者组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.