Apache Kafka 4 cheatsheet

Apache Kafka 4: Producing and consuming

5 common Apache Kafka 4 tasks.

Send messages from the terminal

Type one message per line. Press Ctrl+C to stop.

bin/kafka-console-producer.sh --topic orders --bootstrap-server localhost:9092

Send keyed messages

Type key:value pairs. Messages with the same key go to the same partition.

bin/kafka-console-producer.sh --topic orders --bootstrap-server localhost:9092 --property parse.key=true --property key.separator=:

Read messages from the start

Read a topic from the earliest offset.

bin/kafka-console-consumer.sh --topic orders --from-beginning --bootstrap-server localhost:9092

Show keys and timestamps

Print each message's key and timestamp too.

bin/kafka-console-consumer.sh --topic orders --bootstrap-server localhost:9092 --property print.key=true --property print.timestamp=true

Consume as part of a group

Join a consumer group so the group's offsets are saved.

bin/kafka-console-consumer.sh --topic orders --bootstrap-server localhost:9092 --group order-readers

Was this page helpful?