KafkaConsumer.commitSync / commitAsync是否可以提交未分配分区的偏移量

时间:2020-09-10 11:20:06

标签: java apache-kafka kafka-consumer-api

KafkaConsumer.commitSync(Map<TopicPartition, OffsetAndMetadata> offsets)

可以使用上述方法来提交未分配的TopicPartition的偏移量吗?

我知道ConsumerRebalanceListener.onPartitionsRevoked是在TopicPartition重新平衡之前进行最终偏移提交的正确位置。

但是如果我提交一个分区的偏移量,该分区现在消费者在其分配的列表中没有,例如重新平衡后丢失了,卡夫卡将如何对待?

1 个答案:

答案 0 :(得分:1)

它将引发以下异常:

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)