title: Kafka server contains messages but consumer cannot receive any
body: <p>Using a producer I entered some messages inside Kafka server which is running on localhost. Zookeeper is also on localhost. I have used <code>ConsumerGroupExample</code> as given <a href="https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example" rel="nofollow noreferrer">here</a>. </p>
  
  <p>However, the consumer does not seem to receive any message! the <code>kafka-console-consumer.sh</code> script can pull out all those messages, but the code cannot. What is wrong? The Consumer code is exactly as it is given on that page. </p>
  
  <pre><code>zookeeper="localhost:2181", group id = "test-a", topic = "test". 
  </code></pre>
  
  <p>This is the same topic on which I published messages. Here's code for the producer:</p>
  
  <pre><code>package test;
  
  import kafka.producer.KeyedMessage;
  import kafka.producer.ProducerConfig;
  import java.util.Properties;
  import kafka.javaapi.producer.Producer;
  
  public class KakfaProducer {
      public static void main(String[] args) {
          Properties prop = new Properties();
          prop.put("zookeeper.connect", "localhost:2181");
          prop.put("metadata.broker.list", "localhost:9092");
          prop.put("serializer.class", "kafka.serializer.StringEncoder");
          ProducerConfig producerConfig = new ProducerConfig(prop);
          Producer&lt;String, String&gt; producer = new&lt;String, String&gt; Producer(producerConfig);
          Task t = new Task(producer);
          Thread newThread = new Thread(t);
          newThread.start();
      }
  }
  
  class Task implements Runnable {
      Producer&lt;String, String&gt; producer;
  
      public Task(Producer producer) {
          this.producer = producer;
      }
  
      public void run() {
          long num = 1;
          while (true) {
              String topic = "test";
              KeyedMessage&lt;String, String&gt; message = new&lt;String, String&gt; KeyedMessage(topic, "Hello Test message " + num);
              producer.send(message);
              synchronized (this) {
                  num++;
              }
              if (num % 1000 == 0) {
                  System.out.println("Total messages sent by Thread-" + Thread.currentThread().getId() + num);
              }
          }
      }
  }
  </code></pre>