kafka auto-offset-reset取值:earliest、latest、none的含义

说明

下面各值的前提条件相同:当各分区下有已提交的offset时,但之后的行为不同

earliest

当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费

latest(默认取值)

当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据

演示

  1. 新建主题
    bin/kafka-topics.sh --bootstrap-server hadoop1:9092 --create --topic userlog26
    
  2. 启动 sell 生产者,生产消息:1、2、3、4
    bin/kafka-console-producer.sh --broker-list hadoop1:9092 --topic userlog26
    
  3. 启动服务,获取不到上面的消息
  4. 查看 消费者组详细信息,发现 offset已经更新到 4
    bin/kafka-consumer-groups.sh --bootstrap-server hadoop1:9092 --group test-consumer-group4 --describe
    

none

各分区都存在已提交的offset时,从offset后开始消费;只要有一个分区不存在已提交的offset,则抛出异常


原文出处:/show_1IX2KraHbmbI.html