一个未分配分区的偏移量可以通过 KafkaConsumer.commitSync/commitAsync 提交吗?

huangapple go评论74阅读模式
英文:

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&lt;TopicPartition, OffsetAndMetadata&gt; 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 &quot;main&quot; 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)

huangapple
  • 本文由 发表于 2020年9月10日 19:20:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63828601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定