Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can different Kafka topics have different retention lengths?

Tags:

apache-kafka

I'm looking to have a master topic (with log retention 7 days) and several smaller topics with a filtered corpus with a smaller log retention (2 days). Is this possible?

NOTE: I'm using Kafka v0.10.1.1.

like image 647
bm1729 Avatar asked Feb 21 '17 11:02

bm1729


People also ask

How long are Kafka messages retained?

log.retention.hours The most common configuration for how long Kafka will retain messages is by time. The default is specified in the configuration file using the log. retention. hours parameter, and it is set to 168 hours, the equivalent of one week.

What is the default retention period for a Kafka topic?

We can notice here that the default retention time is seven days.

How do I change the retention period in Kafka topic?

With the kafka-configs command you can inspect any of the topic configs, along with that you can alter them too. So I'm going to alter the retention.ms and set it to 30 minutes (30 minutes * 60 seconds * 1000 milliseconds = 1,800,000 milliseconds).

How do you find the retention period of a Kafka topic?

If you want to view the configurations for all topic Either you can view these properties log. retention. hours or log.retention.ms in server. properties in kafka config directory.


1 Answers

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
like image 184
amethystic Avatar answered Sep 19 '22 16:09

amethystic