原文链接:https://blog.csdn.net/z1941563559/java/article/details/88753938
问题描述:kafka的某些topic在消费完毕后一段时间,重启唯一消费者,offset会重置为最小offset重新消费,一直导致kafka消费的重复消费问题。
问题产生原因:是offset信息过期导致的。我一直以为消费者保持在线,最新位移信息是不会过期的。但即使消费者在线,位移信息也会如约过期。配置的数据保留时间log.retention.hours=168小时比位移保留时间offsets.retention.minutes=1440即24小时要长。offset信息过期后,重启消费者。由于找不到offset信息,会根据配置auto.offset.reset=earliest从最小位移开始消费,导致之前已经消费的数据再次被消费。
解决方案:
原文 :https://issues.apache.org/jira/browse/KAFKA-3806
在特殊情况下,将log.retention.hours(168小时= 7天)和offsets.retention.minutes(1440分钟= 1天)的默认值结合使用可能很危险。偏移保留应始终大于对数保留。
我们已经观察到以下情况和问题:
解决此问题的已知解决方法:
提案:
修改:
默认参数 offsets.retention.minutes & log.retention.minutes 的默认值问题。
默认参数前者是7天,后者是24小时。会导致数据虽然保存但offset失效导致客户端数据重复消费的问题。
0.10.0.0官方的参数说明:http://kafka.apache.org/0100/documentation.html#log
offsets.retention.minutes
Log retention window in minutes for offsets topic
Kafka Server端保存的offset的过期时间。默认值1440(1440分钟也就是24小时),应该调整为与log.retention.hours一致,即10080。
log.retention.hours & log.retention.minutes
这两个参数都是用来设置删除日志的,无论哪个属性已经溢出,都会进行文件的删除。
log.retention.hours:
The number of hours to keep a log file before deleting it (in hours), tertiary to log.retention.ms property
参数int类型,默认值:168 (168小时也就是7天)。
log.retention.minutes:
The number of minutes to keep a log file before deleting it (in minutes), secondary to log.retention.ms property. If not set, the value in log.retention.hours is used
参数int类型,默认值:null。
原文:https://www.cnblogs.com/lshan/p/12573631.html