Apache Kafka for Beginners (Part 3 — Producer & consumer)
Producer & Consumer
Create topic
open different new terminal, go to kafka folder and run / type
$ ./bin/kafka-topics.sh — create — zookeeper localhost:2181 — replication-factor 1 — partitions 1 — topic test
Run consumer
open different new terminal, go to kafka folder and run / type
$ ./bin/kafka-console-consumer.sh — bootstrap-server localhost:9092 — topic test
Run producers
open different new terminal, go to kafka folder and run / type
$ ./bin/kafka-console-producer.sh — broker-list localhost:9092 — topic test
type something in the new line in the producer screen
> test one
> test two
open the consumers terminal and the results will be
test one
test two
try to type something in your producer terminal, it will shown in your consumer terminal
Run consumer message from beginning
lets try to retrieve all message from beginning in the topic `test`
open different new terminal, go to kafka folder and runt / type
the syntax is the same in the consumer but added ` — from-beginning`
$ ./bin/kafka-console-consumer.sh — bootstrap-server localhost:9092 — topic test — from-beginning
Run consumer with specific offset message
you can get message in specified offset just add ` — offset <offset>`
in case we want to retrieve message from offset 1 (in kafka, offset start from 0)
$ ./bin/kafka-console-consumer.sh — bootstrap-server localhost:9092 — topic test — offset 1 — partition 0
<< Part 2 — Apache Kafka for Beginners (Part 2 — Install Kafka)
Part 4— Apache Kafka for Beginners (Part 4—Partition & Replication) >>