卡夫卡提交偏移量
如果Kafka中手动提交偏移量,失败时会发生什么? 示例->假设偏移量 0 已提交,偏移量 1 未提交,然后偏移量 2 已提交。偏移量1处的消息是否重试?
In case of manual commit offset in Kafka, what happens when there is a failure?
Example -> Lets assume offset 0 is committed, offset 1 is not committed and then offset 2 is committed. Is the message at offset 1 retried?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您的提交方式:
在
commitSync
上,假设您像示例中那样单独提交每个偏移量,如果未提交偏移量 1,它将重试提交该偏移量,直到成功或遇到不可重试的失败。该机制的一个缺点是应用程序会被阻塞,直到代理做出响应,从而限制了应用程序的吞吐量。
另一方面,在 commitAsync 上,如果提交偏移量 1 失败,则不会重试。原因是,当代理响应返回 Kafka 客户端时,可能会稍后提交那已经成功了。
想象一下,在您的示例中,由于临时网络问题,偏移量为 1 的消息提交失败。同时,应用程序已经成功处理了偏移量为 2 的消息。如果我们现在重试之前失败的提交,则可能会在已提交 2 之后成功提交偏移量 1。在重新平衡的情况下,这将导致更多重复。
It depends on how you commit:
On
commitSync
assuming you commit each offset separately like in your example, if offset 1 is not committed it will retry to commit that offset until it succeeds or until it encounters nonRetryable failure.One drawback of that mechanism is that the application is blocked until the broker responds and therefor limit the application throughput.
On
commitAsync
on the other hand, there is no retry in case it failed to commit offset 1. The reason for that is that by the time the broker responds get back to your Kafka client there may be later commit that was already successful.Imagine on your example that commit of message with offset 1 was failed due to temporary network issue. Meanwhile the application already processed successfully message with offset 2. If we now retry previous failed commit it might succeed to commit offset 1 after 2 was already committed. In a case of rebalance, this will cause more duplicated.