如何无限期存储Kafka事件?Broker配置参数确认
Great question! Let me break this down based on hands-on experience with Kafka 2.2.0 (bundled with Confluent 5.2.1):
1. Are log.retention.ms=-1 and log.retention.bytes=-1 valid for infinite retention?
Absolutely. Even if the official docs don’t explicitly label this as "infinite retention", setting these parameters to -1 is the de facto standard approach to disable time-based and size-based log retention in this version.
log.retention.ms=-1turns off automatic deletion of log segments based on their agelog.retention.bytes=-1turns off automatic deletion triggered by the total size of log segments for a topic
This combination ensures Kafka won’t remove your events due to hitting a time or size threshold.
2. Are these two parameters enough?
Almost, but there’s one more critical setting to verify to guarantee full infinite retention:
log.cleanup.policy: The default value isdelete, which pairs perfectly with your existing configs. However, if this is set tocompactordelete,compact, Kafka will still perform log compaction—removing older records with duplicate keys, even when retention time/size limits are disabled.
If your goal is to retain every single event (including duplicates), make sure log.cleanup.policy stays set to delete.
Quick verification tip
To confirm your settings are working as expected:
- Check the broker logs for any messages about log segment deletion (you shouldn’t see any for topics using these configs)
- Use the
kafka-log-dump.shtool to inspect log segments for a test topic—you’ll see all your events remain intact over time
内容的提问来源于stack exchange,提问作者J S

