Skip to content
Advertisement

Can an offset of an unassigned partition be committed by KafkaConsumer.commitSync/commitAsync

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?

Advertisement

Answer

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)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement