Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I code to store the data permanently in Kafka?

I have read the documentation but still unable to figure out where to insert the command so that my topic stores the logs forever?

like image 208
hasherBaba Avatar asked Nov 25 '25 13:11

hasherBaba


2 Answers

There are properties like log.retention.hours, log.retention.bytes which controls for much time these logs will be retained. You can set both of these properties to -1 to retain your logs forever.

like image 180
pulkit-singhal Avatar answered Nov 28 '25 15:11

pulkit-singhal


As @pulkit-singhal said, you can configure the retention period as a server default in the server.properties - for full details see the reference doc. You can also set it per-topic using kafka-topics.sh.

You also should be aware of the concept of Log Compaction, which is another way of enabling infinite retention and is commonly used. This gives you a way to retain for every given key, the latest value. Log compaction is enabled by setting log.cleanup.policy=compact

Which you use (-1 as the time & size retention policy, or log compaction) depends on your use case.

like image 44
Robin Moffatt Avatar answered Nov 28 '25 17:11

Robin Moffatt