Caused by: org.apache.kafka.clients.consumer.NoOffsetForPartitionException: Undefined offset with no reset policy for partitions: [test-topic-1]
这是因为设置的auto.offset.reset为none,表示如果在kafka broker中找不到当前消费者组的offset时,则抛出异常。
下面是源码中的解释:
/**
* <code>auto.offset.reset</code>
*/
public static final String AUTO_OFFSET_RESET_CONFIG = "auto.offset.reset";
public static final String AUTO_OFFSET_RESET_DOC = "What to do when there is no initial offset in Kafka or if the current offset does not exist any more on the server (e.g. because that data has been deleted): <ul><li>earliest: automatically reset the offset to the earliest offset<li>latest: automatically reset the offset to the latest offset</li><li>none: throw exception to the consumer if no previous offset is found for the consumer's group</li><li>anything else: throw exception to the consumer.</li></ul>";
因此,可以根据需求设置成earliest或latest。
本文深入探讨了Kafka中NoOffsetForPartitionException异常的原因,即当auto.offset.reset配置为none时,若消费者组未找到offset将抛出此异常。文章提供了源码级解释,并建议可根据需求设置auto.offset.reset为earliest或latest。
3782

被折叠的 条评论
为什么被折叠?



