kafka消费者停止2天offset元信息丢失

背景:因下游服务还没做好,所以下游服务暂时停机了,上游一直往kafka发送消息,打算下游上线时能直接接上停机前的位置,于是把topic的retention.ms设置成了2周,保证log不过期,过了两天想查看下topic堆积情况(怎么查看可看另一篇文章),结果根据group查不到分区与消费者绑定关系了,offset信息就也不存在了

[xuhaixing@xhx151 kafka_2.13-2.7.0]$ kafka-consumer-groups.sh --bootstrap-server http://192.168.94.151:9092 --describe --group goods-sync-group

Error: Consumer group 'goods-sync-group' does not exist.

抱着试一试的态度,把消费者启动了下,真的是从最新位置开始消费的。

问题分析

当时只把日志过期时间调大了,以为消费者的offset信息会一直保存直到日志过期,后来经查看资料,offset过期时间也是单独配置的offsets.retention.minutes

官网有如下描述,2.0.0版本后,offset过期时间由1天变成了7天。

Notable changes in 2.0.0
KIP-186 increases the default offset retention time from 1 day to 7 days. This makes it less likely to “lose” offsets in an application that commits infrequently. It also increases the active set of offsets and therefore can increase memory usage on the broker. Note that the console consumer currently enables offset commit by default and can be the source of a large number of offsets which this change will now preserve for 7 days instead of 1. You can preserve the existing behavior by setting the broker config offsets.retention.minutes to 1440.

所以,日志不过期并不能保证消费者停止后,还能从以前的offset继续消费。

解决

  1. 消费者启动时,指定从某个offset开始消费,或者从某个时间戳开始消费。
  2. 消费者pause住,然后再resume,此种情况下消费者不消费消息,但是一直和broker间有心跳。
  3. 调大broker端参数offsets.retention.minutes,可以保持和log过期时间一致

当时想投机取巧一下不想改代码,没想到还是改代码了。

更多优质内容,请关注公众号:程序员星星toC

imgcode.jpg

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值