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.

  1. Message Keys

  2. Acknowledgment

  1. Message Keys

    1. Write messages to specific partitions is possible by the message keys.
    2. Each messages should send the value of key to publish data to a particular topic's partition.
    3. If you send key=NULL, it will be distributed to each partition in a round-robin fashion.
    4. If you send same key each time, all messages will be published to the same partition.
    5. The load balancing comes in process if you don't pass key.
  2. Acknowledgment

    1. Kafka Acknowledgment is Producer Acks setting.
    2. Kafka Acknowledgment(Acks) is one of the process to receive acknowledgment of data publish/write.
    3. Kafka Acknowledgment(Acks) provides confirmation acknowledgment to consumer/sender of data received.
    4. here are three confirmation or acknowledgment.
      1. acks=0

      2. 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.
      3. acks=1

        (limited data loss).
      4. 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.
      5. acks=all

        (no data loss).
      6. 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