I show two methods to clear out a Kafka topic:
The first method works fine for non-production scenarios where you can stop all of the producers and consumers, but let’s say that you want to flush the topic while leaving your producers and consumers up (but maybe you have a downtime window where you know the producers aren’t pushing anything). In this case, we can change the retention period to something very short, let the queue flush, and bring it back to normal, all using the kafka-configs shell script.
Points deducted for slipping and writing “queue” there, but otherwise, I prefer the second method, as things are still online. In less-extreme scenarios, you might drop the retention period to a few minutes, especially if your consumers are all caught up.