1. Delete the topic
Add settings in server.properties, not enabled by default
delete.topic.enable=true
delete topic command
/bin/kafka-topics --delete --topic test --zookeeper localhost:2181
2. Delete theme data
If you want to keep the topic, just delete the existing data (log) of the topic. This can be achieved by modifying the data retention time
bin/kafka-configs --zookeeper localhost: 2181 --entity-type topics --entity-name test --alter --add-config retention.ms= 3000 ### Modify retention time to three seconds, but not after modification It will be deleted immediately in three seconds. Kafka adopts the method of rotation training. When the topic is trained in rotation, it is found that the data three seconds ago are deleted. The time is set by yourself in server.properties, see below for the settings.
After the data is deleted, if you continue to use the theme, the retention time of the theme data cannot be three seconds, so delete the modified configuration above and use the unified configuration in server.properties.
bin/kafka-configs --zookeeper localhost:2181 --entity-type topics --entity-name test --alter --delete-config retention.ms
Configuration of data retention time in server.properties
log.retention.hours= 168 // Retention time, in hours log.retention.check.interval.ms= 300000 // Retention time check interval, in milliseconds
ref: https://blog.csdn.net/forrest_ou/article/details/78999983