Publish Subscribe

  1. Create Topic.
    1. ./kafka-topics.sh --create --topic example-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1
  2. Check is the topic created.
    1. ./kafka-topics.sh --list --bootstrap-server localhost:9092
  3. In the second window, run the Console Consumer.
    1. ./kafka-console-consumer.sh --topic example-topic --bootstrap-server localhost:9092
  4. Go back to the previous window and run the message producer.
    1. ./kafka-console-producer.sh --topic example-topic --bootstrap-server localhost:9092
  5. Publish a few messages, confirming each of them with the Enter button.
  6. The messages should appear in the terminal window launched in point 4
  7. Close the Kafka Consumer process launched in point 4.
  8. Try to read the published messages again.
    1. ./kafka-console-consumer.sh --topic example-topic --bootstrap-server localhost:9092
  9. After running the command above, you will not observe any result because the messages were published to the Topic before the Consumer was connected. To read the Topic from the beginning, you need to call the same command adding the --from-beginning parameter.
  10. 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="-".