kafkaconsumer.commitsync/commitsync是否可以提交未分配分区的偏移量

agxfikkp  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(358)
KafkaConsumer.commitSync(Map<TopicPartition, OffsetAndMetadata> offsets)

上面的方法可以用于提交未分配主题分区的偏移量吗?
我知道 ConsumerRebalanceListener.onPartitionsRevoked 是在主题分区重新平衡之前执行最终偏移提交的正确位置。
但是,如果我提交了一个分区的偏移量,而消费者现在在其分配的列表中没有这个分区,例如它在重新平衡后丢失了它,那么kafka将如何处理它呢?

3okqufwl

3okqufwl1#

它将引发以下异常:

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)

相关问题