英文:
Can an offset of an unassigned partition be committed by KafkaConsumer.commitSync/commitAsync
问题
KafkaConsumer.commitSync(Map<TopicPartition, OffsetAndMetadata> offsets)
以上方法可用于提交尚未分配的TopicPartition的偏移量吗?
我知道ConsumerRebalanceListener.onPartitionsRevoked
是在TopicPartition重新平衡之前进行最终偏移量提交的正确位置。
但是,如果我提交了一个分区的偏移量,而消费者现在在其分配的列表中没有该分区,例如,在重新平衡后丢失了该分区,Kafka会如何处理它?
英文:
KafkaConsumer.commitSync(Map<TopicPartition, OffsetAndMetadata> offsets)
Can above method be used to commit offset of an unassigned TopicPartition ?
I know ConsumerRebalanceListener.onPartitionsRevoked
is the right place to do final offset commit before TopicPartition rebalance.
But if I commit offset of a partition which consumer does not have in its assigned list now, e.g. it lost it after rebalance, how will Kafka treat it?
答案1
得分: 2
它将抛出以下异常:
在线程 "main" 中的异常 org.apache.kafka.clients.consumer.CommitFailedException:由于消费者不是自动分配分区的活动组的一部分,无法完成偏移量提交;很可能消费者已被从组中踢出。
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.sendOffsetCommitRequest(ConsumerCoordinator.java:1109)
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.commitOffsetsSync(ConsumerCoordinator.java:976)
at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1511)
at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1459)
英文:
It will throw the following Exception:
Exception in thread "main" org.apache.kafka.clients.consumer.CommitFailedException: Offset commit cannot be completed since the consumer is not part of an active group for auto partition assignment; it is likely that the consumer was kicked out of the group.
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.sendOffsetCommitRequest(ConsumerCoordinator.java:1109)
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.commitOffsetsSync(ConsumerCoordinator.java:976)
at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1511)
at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1459)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论