title: Make kafka consumer run forever
body: <p>I wrote a <a href="https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example" rel="nofollow">high level Kafka consumer</a> as a part of a java application.</p>
  
  <p>So the core code looks like this:</p>
  
  <pre><code>public void start() {
      ConsumerConnector consumerConnector = conf.getConsumerConnector();
      String topic = conf.getTopic();
      int numOfThereads = conf.getNumOfThreads();
  
      Map&lt;String, Integer&gt; topicCountMap = ImmutableMap.of(topic, numOfThereads);
      Map&lt;String, List&lt;KafkaStream&lt;Message&gt;&gt;&gt; topicMessageStreams = consumerConnector.createMessageStreams(topicCountMap);
      List&lt;KafkaStream&lt;Message&gt;&gt; streams = topicMessageStreams.get(topic);
  
      // create 4 threads to consume from each of the partitions
      executor = Executors.newFixedThreadPool(numOfThereads);
  
      // consume the messages in the threads
      for (final KafkaStream&lt;Message&gt; stream : streams) {
          executor.submit(new ConsumerThread(stream));
      }
  }
  </code></pre>
  
  <p>To test my consumer I also created a producer, wrote to kafka and then launched my consumer, it works.
  Since the threads are executed inside a loop I'm not sure I get things right.
  I would like my consumer to run forever and keep on consuming messages from kafka.</p>
  
  <p>What is the right way to make it run forever?</p>