title: How to subscribe to the topic in apache kafka from the java application?
body: <p>This is the consumer for the apache kafka and it is not getting the messages from the topic "test"</p>
  
  <pre><code>package com.kafka;
  
  import java.util.Arrays;
  import java.util.Properties;
  
  import org.apache.kafka.clients.consumer.ConsumerRecord;
  import org.apache.kafka.clients.consumer.ConsumerRecords;
  import org.apache.kafka.clients.consumer.KafkaConsumer;
  
  public class ConsumerTest {
  
    public static void main(String[] args) {
       Properties props = new Properties();
       props.put("bootstrap.servers", "172.17.210.45:9092");
       props.put("zookeeper.connect", "172.17.210.45:2181");
       props.put("group.id", "test-consumer-group");
       props.put("enable.auto.commit", "true");
       props.put("auto.commit.interval.ms", "1000");
       props.put("auto.offset.reset", "earliest");
       props.put("session.timeout.ms", "30000");
       props.put("key.deserializer",  "org.apache.kafka.common.serialization.StringDeserializer");
       props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
  
       KafkaConsumer&lt;String, String&gt; kafkaConsumer = new KafkaConsumer&lt;&gt;(props);
       System.out.println("properties loaded");
       kafkaConsumer.subscribe(Arrays.asList("test"));
  
       while (true) {
           ConsumerRecords&lt;String, String&gt; records = kafkaConsumer.poll(100);
           for (ConsumerRecord&lt;String, String&gt; record : records) {
             System.out.printf("offset = %d, value = %s", record.offset(), record.value());
             System.out.println();
           }
       }
  
    }
  }
  </code></pre>
  
  <p>In this result am not getting any messages from the apache kafka.</p>
  
  <pre><code>     log4j:WARN No appenders could be found for logger                                                                                                                (org.apach  e.kafka.clients.consumer.ConsumerConfig).
       log4j:WARN Please initialize the log4j system properly.
  properties loaded
  </code></pre>