title: Kafka Consumer WakeupException Handling Java
body: <p>if I run the <code>kafka</code> consumer inside a thread without manipulating it from outside, like put the consumer on sleep or wake him up, it is necessary to handle the <code>WakeupException</code> properly? And what is a good approach to handle it?</p>
  
  <p>The consumer is running on an webservice for pulling constantly data out of a queue and should never stop doing it. Furthermore the service has no idle or suspend state. In the documentation of Kafka it is pointed out that the exception is only thrown when the kafka consumer is blocked by another thread, but that will never happen. <a href="https://kafka.apache.org/0100/javadoc/org/apache/kafka/common/errors/WakeupException.html" rel="noreferrer">https://kafka.apache.org/0100/javadoc/org/apache/kafka/common/errors/WakeupException.html</a></p>
  
  <p>Kafka Version 0.10.0.0</p>
  
  <pre class="lang-java prettyprint-override"><code>catch (WakeupException e) {
      LOG.info("Kafka Consulmer wakeup exception");
      // Ignore exception if closing
      if (!closed.get()) {
          throw e;
      }
  } finally {
      consumer.close();
  }
  </code></pre>
  
  <p>Regards,
  Rakesh</p>