Reputation: 294
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?
Upvotes: 1
Views: 364
Reputation: 18475
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)
Upvotes: 2