Can different Kafka topics have different retention lengths?

log.retention.ms, whose default value is 7 days, is at the global level for all topics, whereas you could override it using a topic-level config retention.ms when creating the topic as below:

bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic test 
--partitions 1 --replication-factor 1 --config retention.ms=172800000

log.retention.hours is a property of a broker which is used as a default value when a topic is created. When you change configurations of currently running topic using kafka-topics.sh, you should specify a topic-level property.

A topic-level property for log retention time is retention.ms.

From Topic-level configuration in Kafka 0.10.1 documentation:

Property: retention.ms Default: 7 days Server Default Property: log.retention.minutes Description: This configuration controls the maximum time we will retain a log before we will discard old log segments to free up space if we are using the "delete" retention policy. This represents an SLA on how soon consumers must read their data. So the correct command is

$ bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic as-access --config retention.ms=172800000 You can check whether the configuration is properly applied with the following command.

$ bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic as-access Then you will see something like below.

Topic:as-access PartitionCount:3 ReplicationFactor:3 Configs:retention.ms=172800000

Tags:

Apache Kafka