Apache Kafka for Beginners (Part 3 — Producer & consumer)

Buyung Hardiansyah
2 min readOct 10, 2019

--

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) >>

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Buyung Hardiansyah
Buyung Hardiansyah

Written by Buyung Hardiansyah

Software Developer -- Golang | Python | PHP | Reactjs | Flutter

No responses yet

Write a response