Last active
February 12, 2022 11:38
-
-
Save mjedynak/e47088b796a29e5c6636117ad38fdb9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
class TopicPurger(private val adminClient: AdminClient) { | |
fun purge(topicName: String) { | |
val topicDescription = adminClient.describeTopics(listOf(topicName)).all().get()[topicName] | |
val partitionSize = topicDescription?.partitions()?.size | |
val recordsToDelete = (0..partitionSize!!).associate { partitionIndex -> | |
TopicPartition(topicName, partitionIndex) to RecordsToDelete.beforeOffset(-1) | |
} | |
adminClient.deleteRecords(recordsToDelete) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment