title: Why doesn't offset get updated when messages are consumed in Kafka
body: <p>I am implementing Kafka consumer class to receive messages. I wanted to only get the new messages every time. Therefore, I set <code>enable.auto.commit</code> true. However the offset does not seem to change at all. Even though the topic, consumer group and partition has been always the same. </p>
  
  <p>Here is my consumer code:</p>
  
  <pre><code>    consumerConfig.put("bootstrap.servers", bootstrap);
      consumerConfig.put("group.id", KafkaTestConstants.KAFKA_GROUP);
      consumerConfig.put("enable.auto.commit", "true");
      consumerConfig.put("auto.offset.reset", "earliest");
      consumerConfig.put("auto.commit.interval", 1000);
      consumerConfig.put("key.deserializer", StringDeserializer.class.getName());
      consumerConfig.put("value.deserializer", StringDeserializer.class.getName());
      StringDeserializer deserializer = new StringDeserializer();
      KafkaConsumer&lt;String, String&gt; kafkaConsumer = new KafkaConsumer&lt;&gt;(consumerConfig, deserializer, deserializer);
  
      TopicPartition tp = new TopicPartition(KafkaTestConstants.KAFKA_TOPIC, 0);
      List&lt;TopicPartition&gt; tps = Arrays.asList(tp);
      kafkaConsumer.assign(tps);
      long offset = kafkaConsumer.position(tp);
      System.out.println("Offset of partition: " + offset);
  
      List&lt;String&gt; messages = new ArrayList&lt;String&gt;();
      ConsumerRecords&lt;String, String&gt; records = kafkaConsumer.poll(100);
  
      for (ConsumerRecord&lt;String, String&gt; record : records) {
          System.out.println("Message received: " + record.value());
          messages.add(record.value());
      }
  
      consumer.commitAsync();
      System.out.println("Offset commited.\n");
      consumer.close();
  </code></pre>
  
  <p>No matter how many times I run it, it always shows the offset is 0. Therefore, it always receive all messages from the very beginning. What am I missing?</p>
  
  <p><strong>EDIT:</strong> Based on Matthias's answer, I decided to manually commit the offset. However <code>commitSync()</code> would hang. <code>commitAsync()</code> sort of works. I will explain the "sort of" later. Here is what the code does:</p>
  
  <pre><code>producer send 2 messages;
  consumer initiates;
  print out current position;
  consumer.poll();
  print received messages;
  consumer.commitAsync();
  </code></pre>
  
  <p>This is how this code behaves. Say I have 100 messages. Now producers sends 2 new messages. Before consumer poll, it would show current offset position as 102 which is supposed to be 100. Therefore, no new messages will be printed out. It is almost like the offset is updated after producer sent the messages. </p>