title: Kafka - What are the better alternatives than poll() to listen to a topic in Java?
body: <p>I'm trying to create a consumer client in Java. I realized the poll() function is depreciated. What are the alternatives to listen to a topic of Kafka?</p>
  
  <p>My code:</p>
  
  <pre><code>KafkaConsumer&lt; String, UserSegmentPayload &gt; kc = new KafkaConsumer&lt;&gt;(props2);
  kc.subscribe(Collections.singletonList(topicName));
  while (true) {
      ConsumerRecords&lt;String, UserSegmentPayload&gt; records = kc.poll(100);
      for (ConsumerRecord&lt;String, UserSegmentPayload&gt; record : records) {
          System.out.printf("offset = %d, key = %s, value = %s\n",
          record.offset(), record.key(), record.value());
      }
  }
  </code></pre>