Producer
On this section you will learn what is a Producer and how to work with it via Command Line
What is a Producer?
"Producers publish data to the topics of their choice. The producer is responsible for choosing which record to assign to which partition within the topic"
Producers are responsible for :
Create new messages ( possibly with a schema)
Publish messages to a Topic
It could address the message to a specific partition.
Anatomy of Producer Record
Producer records needs to be formed with a particular data structure. Here is how it looks
Producer Record
Description
topic
Where to send the message to
[ partition ]
On which partition we would like this message to be send to
[ key ]
used for routing, ordering and deduplication
value
the message itself
Let's start producing messages
Kafka provides a way to start producing messages by using the cli with an script called kafka-console-producer
.
Let's do send some messages. We will start producing messages by reading from standard input and writing it to a Topic in Kafka.
Execute the following command:
./kafka-console-producer --topic my-new-topic --broker-list localhost:9092
Have fun and start typing messages within the stdin
Bonus Exercise
Try to send messages with 2 different keys, so we can do routing afterwards with the consumer :-)
Last updated