kafka的新的group订阅到topic中历史消息

1、配置

kafka.consumer.auto.offset.reset=earliest

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值了)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值