title: Kafka - Producer Acknowledgement
body: <p>I saw in a video tutorial that Kafka Broker supports 3 types of acknowledgement when producer posts a message.</p>
  <p>0 - Fire and Forget<br />
  1 - Leader Ack<br />
  2 - Ack of all the brokers</p>
  <p>I am using Kafka's Java API to post message. Is this something that has to be set for each broker using server.properties specific to each broker or is it something that has to be set by producer? If it has to be set by the producer , please explain how it can be set using Java API.</p>
  <pre><code>import org.apache.kafka.clients.producer.KafkaProducer;
  import org.apache.kafka.clients.producer.ProducerRecord;
  import org.apache.kafka.clients.producer.RecordMetadata;
  
  import java.util.Properties;
  
  public class KafkaProducerApp {
  
      public static void main(String[] args){
          Properties properties = new Properties();
          properties.put(&quot;bootstrap.servers&quot;,&quot;localhost:9092,localhost:9093,localhost:9094&quot;);
          properties.put(&quot;key.serializer&quot;,&quot;org.apache.kafka.common.serialization.StringSerializer&quot;);
          properties.put(&quot;value.serializer&quot;,&quot;org.apache.kafka.common.serialization.StringSerializer&quot;);
  
          KafkaProducer&lt;String,String&gt; kafkaProducer = new KafkaProducer&lt;String, String&gt;(properties);
  
          try{
              for(int i=0;i&lt;150;i++) {
                  RecordMetadata ack = kafkaProducer.send(new ProducerRecord&lt;String, String&gt;(&quot;replicated_topic&quot;, Integer.toString(i), &quot;MyMessage&quot; + Integer.toString(i))).get();
                  System.out.println(&quot; Offset = &quot; + ack.offset());
                  System.out.println(&quot; Partition = &quot; + ack.partition());
              }
          } catch (Exception ex){
              ex.printStackTrace();
          } finally {
              kafkaProducer.close();
          }
  
  
  
      }
  
  }
  </code></pre>