码迷,mamicode.com
首页 > 其他好文 > 详细

关于kafka的新的group无法订阅到topic中历史消息的问题

时间:2018-05-21 14:50:16      阅读:516      评论:0      收藏:0      [点我收藏+]

标签:eset   top   就是   往里面   关于   row   serve   意思   HERE   

今天在写kafka的java api例子时候,遇到一个问题,比如我创建了一个test主题,往里面写了1,2,3,4,5条消息,在这个时候,我用一个新的group启动了一个消费者,发现该消费者只能读到5以后的消息,而1到5的消息是读不到的,于是感到疑惑,就去官网上找了一下,看到这这样一个配置项“auto.offset.reset”,该配置项的描述如下:

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):

  • earliest: automatically reset the offset to the earliest offset
  • latest: automatically reset the offset to the latest offset
  • none: throw exception to the consumer if no previous offset is found for the consumer‘s group
  • anything else: throw exception to the consumer.

大概意思是,当无法获取当前offset的时候该怎么处理,这个配置项的默认值是“latest”,而当我们新建一个group对主题订阅的时候,第一次应该是符合这个要求的(无法知道当前的offset值),这个时候就触发了“latest”这个配置值对应的操作,也就是说把当前topic里面最新的偏移作为offset,那显然,该消费者是读不到主题中的历史信息的,于是把配置的值改为“earliest”,发现正常了,

 

需要注意的是,这个配置只在group第一次订阅主题的时候触发,一旦这个offset值被确定下来了,你再把这个配置改成“earliest”就没效果了,因为他已经不符合这个条件了(这个group在这个主题下已经能拿到offset值了)

关于kafka的新的group无法订阅到topic中历史消息的问题

标签:eset   top   就是   往里面   关于   row   serve   意思   HERE   

原文地址:https://www.cnblogs.com/cxhfuujust/p/9066517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!