How to purge or delete messages in a Kafka topic? - Big Data In Real World

How to purge or delete messages in a Kafka topic?

What is the difference between hadoop fs, hadoop dfs and hdfs dfs commands?
December 25, 2020
How to delete a Kakfa topic?
December 30, 2020
What is the difference between hadoop fs, hadoop dfs and hdfs dfs commands?
December 25, 2020
How to delete a Kakfa topic?
December 30, 2020

The easiest way to purge or delete messages in a Kafka topic is by setting the retention.ms to a low value. retention.ms configuration controls how long messages should be kept in a topic. Once the age of the message in a topic hits the retention time the message will be removed from the topic.

Note the below steps delete or purge messages in your topic. Use precaution when executing the below.

Checking the current retention value for a topic

Check and record the current retention value of the topic. You need to know the current retention value for rollback after you purge the messages.

 kafka-configs --zookeeper <zkhost>:2181 --describe --entity-type topics --entity-name <topic name>

Update retention value on a topic

-add-config retention.ms=1000 updates the retention time or TTL (Time To Live) of messages in the topic. It is in milliseconds and hence the below command will update the topic with the retention time less than a minute.

After the update, the messages which are older than the retention time in the topic will be deleted or purged.

kafka-configs.sh --zookeeper <zkhost>:2181 --entity-type topics --alter --entity-name <topic name> --add-config retention.ms=10000

 

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.
How to purge or delete messages in a Kafka topic?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X