title: Apache Kafka: Exactly Once in Version 0.10
body: <p>To achieve exactly-once processing of messages by Kafka consumer I am committing one message at a time, like below</p>
  
  <pre><code>public void commitOneRecordConsumer(long seconds) {
          KafkaConsumer&lt;String, String&gt; consumer = consumerConfigFactory.getConsumerConfig();
  
          try {
  
              while (running) {
                  ConsumerRecords&lt;String, String&gt; records = consumer.poll(1000);
                  try {
                      for (ConsumerRecord&lt;String, String&gt; record : records) {
  
                          processingService.process(record);
  
                          consumer.commitSync(Collections.singletonMap(new TopicPartition(record.topic(),record.partition()), new OffsetAndMetadata(record.offset() + 1)));
  
                          System.out.println("Committed Offset" + ": " + record.offset());
  
                      }
                  } catch (CommitFailedException e) {
                      // application specific failure handling
                  }
              }
          } finally {
              consumer.close();
          }
      }
  </code></pre>
  
  <p>The above code delegates the processing of message asynchronously to another class below.</p>
  
  <pre><code>@Service
  public class ProcessingService {
  
      @Async
      public void process(ConsumerRecord&lt;String, String&gt; record) throws InterruptedException {
          Thread.sleep(5000L);
          Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
          map.put("partition", record.partition());
          map.put("offset", record.offset());
          map.put("value", record.value());
          System.out.println("Processed" + ": " + map);
      }
  
  }
  </code></pre>
  
  <p>However, this still does not guarantee exactly-once delivery, because if the processing fails, it might still commit other messages and the previous messages will never be processed and committed, what are my options here?</p>