šŸ›  Kafka Cheatsheet: Core Commands

šŸ”¹ Topic Management

# List all topics
kafka-topics.sh --list --bootstrap-server localhost:9092

# Create a topic
kafka-topics.sh --create --bootstrap-server localhost:9092 \
--replication-factor 1 --partitions 3 --topic my-topic

# Describe a topic
kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic my-topic

# Delete a topic
kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic my-topic


šŸ”¹ Producing Messages

# Start a console producer
kafka-console-producer.sh --broker-list localhost:9092 --topic my-topic

# With key support
kafka-console-producer.sh --broker-list localhost:9092 --topic my-topic --property "parse.key=true" --property "key.separator=:"


šŸ”¹ Consuming Messages

# Start a console consumer
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning

# Consume with key display
kafka-console-consumer.sh --bootstrap-server localhost:9092 \
--topic my-topic --property print.key=true --property key.separator=":" --from-beginning

# Consume from a specific group
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --group my-group


šŸ”¹ Consumer Groups

# List consumer groups
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

# Describe a consumer group
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group

# Reset offsets (example: to earliest)
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--group my-group --topic my-topic --reset-offsets --to-earliest --execute


šŸ”¹ Broker Info & Cluster Metadata

# Describe cluster
kafka-broker-api-versions.sh --bootstrap-server localhost:9092

šŸ”¹ Utilities

# Check offsets of a topic/partition
kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic my-topic

# Create a Kafka topic with zookeeper (old style)
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic my-topic

Back to blog

Leave a comment