Apache Kafka 4 cheatsheet
Apache Kafka 4: Topics
7 common Apache Kafka 4 tasks.
Create a topic
Create a topic with three partitions.
bin/kafka-topics.sh --create --topic orders --bootstrap-server localhost:9092 --partitions 3 --replication-factor 1
List topics
Show the topics in the cluster.
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
Describe a topic
Show partitions, leaders and replicas.
bin/kafka-topics.sh --describe --topic orders --bootstrap-server localhost:9092
Add partitions
Increase a topic's partition count. You can't reduce it.
bin/kafka-topics.sh --alter --topic orders --partitions 6 --bootstrap-server localhost:9092
Caution: Adding partitions changes which partition a key maps to, which can break ordering per key.
Delete a topic
Delete a topic and its data.
bin/kafka-topics.sh --delete --topic orders --bootstrap-server localhost:9092
Caution: Permanently deletes the topic's messages.
Set a topic's retention
Keep messages for 7 days.
bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name orders --add-config retention.ms=604800000
See the latest offsets
Print the end offset of each partition.
bin/kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic orders