Publish and Subscribe with Kafka CLI

- Create Topic.
./kafka-topics.sh --create --topic example-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1
- Check is the topic created.
./kafka-topics.sh --list --bootstrap-server localhost:9092
- In the second window, run the Console Consumer.
./kafka-console-consumer.sh --topic example-topic --bootstrap-server localhost:9092
- Go back to the previous window and run the message producer.
./kafka-console-producer.sh --topic example-topic --bootstrap-server localhost:9092
- Publish a few messages, confirming each of them with the Enter button.
- The messages should be logged in the terminal window launched in point 4.
- Close the Kafka Consumer process launched in point 4.
- Try to read the published messages again.
./kafka-console-consumer.sh --topic example-topic --bootstrap-server localhost:9092
- After running the command, you will not see any result because the messages were published to the topic before the Consumer was connected. To read a topic from the beginning, you need to call the same command adding the
--from-beginning
parameter. - Read all the additional message attributes, you need to add few parameters to the command from the previous point:
--property print.offset=true --property print.partition=true --property print.headers=true --property print.timestamp=true --property print.key=true --property key.separator="-"
.