Cheat Sheet - Kafka

Topic management

Create a topic with the default configuration

kafka-topics.sh --bootstrap-server localhost:9092 --create --topic topic1 --partitions 1 --replication-factor 1

Create a topic where events are never deleted

kafka-topics.sh --bootstrap-server localhost:9092 --create --topic topic2 --config retention.ms=-1

Consumer

Consume from the beginning

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic1 --from-beginning
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic1 --property print.offset=true --from-beginning

Start reading from a specific offset

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic1 --property print.offset=true --offset 2 --partition 0