Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Created December 10, 2018 17:15
Show Gist options
  • Save diasjorge/5a36552b282ffe6e45063a8e0a417469 to your computer and use it in GitHub Desktop.
Save diasjorge/5a36552b282ffe6e45063a8e0a417469 to your computer and use it in GitHub Desktop.
Empty kafka topic
topic="TOPICNAME"
/opt/kafka/bin/kafka-topics.sh --zookeeper $ZOOKEEPERSRV --describe --topic $topic
kconfigs --alter --entity-type topics --entity-name $topic --add-config cleanup.policy=delete
num_partitions=$(/opt/kafka/bin/kafka-topics.sh --zookeeper $ZOOKEEPERSRV --describe --topic $topic | grep PartitionCount | awk '{print $2}' | cut -d: -f 2)
echo '{"partitions": [' > /tmp/offset-file.json
for i in `seq 0 $(($num_partitions - 2))`; do
echo '{"topic": "'$topic'", "partition":'$i', "offset": -1},' >> /tmp/offset-file.json
done
echo '{"topic": "'$topic'", "partition":'$(($num_partitions - 1))', "offset": -1}' >> /tmp/offset-file.json
echo '], "version":1 }' >> /tmp/offset-file.json
/opt/kafka/bin/kafka-delete-records.sh --bootstrap-server localhost:9092 --offset-json-file /tmp/offset-file.json
kconfigs --alter --entity-type topics --entity-name $topic --add-config cleanup.policy=compact
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic $topic --from-beginning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment