Kafka Producer
The kafka Producer is a client application that write messages and sends events to a Kafka cluster.
A Kafka producer sends messages to a topic, where messages are distributed to partitions according key hashing process.
How Kafka Producer Publish Data To The Cluster or Topic?
There are two strategies to publish data to topics.
Message Keys
Acknowledgment
Message Keys
-
- Write messages to specific partitions is possible by the message keys.
- Each messages should send the value of key to publish data to a particular topic's partition.
- If you send key=NULL, it will be distributed to each partition in a round-robin fashion.
- If you send same key each time, all messages will be published to the same partition.
- The load balancing comes in process if you don't pass key.
Acknowledgment
-
- Kafka Acknowledgment is Producer Acks setting.
- Kafka Acknowledgment(Acks) is one of the process to receive acknowledgment of data publish/write.
- Kafka Acknowledgment(Acks) provides confirmation acknowledgment to consumer/sender of data received.
- here are three confirmation or acknowledgment.
-
acks=0
- Possibility of data loss as the producer just sends the data and not wait for the acknowledgment.
If you set acks=0, you won't get the acknowledgment and data may loss in case of brocker down.
acks=1
(limited data loss).
-
This is the default Acknowledgment value. If you set set acks=1, that means an acknowledgment responce is requested,
but there’s no guarantee of replication.
acks=all
(no data loss).
-
If you set set acks=all, that means an acknowledgment responce is requested for replica,
No data loss here as you will get the acknowledgment response of replica.
Read this article of
Create Kafka Producer In Java
producer acknoledgement acks=all
Create Kafka Producer In Java
In the next topic, you will understand about
Kafka Consumer