title: Kafka Consumer with limited number of retries when processing messages
body: <p>I'm having a hard time figuring simple patterns for handling exceptions in the consumer of a Kafka topic.
  Scenario is as follows: in the consumer I call an external service. If the service is unavailable I want to retry a few times and then stop consuming.</p>
  
  <p>The simplest pattern seems a blocking synchronous way of dealing with it, something like this in java:</p>
  
  <pre><code>ConsumerRecords&lt;String, String&gt; records = consumer.poll(100);
  for (ConsumerRecord&lt;String, String&gt; record : records) {
      boolean processed=false;
      int count=0;
      while (!processed) {
          try {
              callService(..); 
          } catch (Exception e) {
              if (count++ &lt; 3) {
                  Thread.sleep(5000);
                  continue;
              } else throw new RuntimeException();
          }
      }
  }
  </code></pre>
  
  <p>However, I have the feeling there must be a simpler approach (without using third party libraries), and one that avoids blocking the thread.</p>
  
  <p>Seems like a common thing we would like to have, yet I could not find a simple example for this pattern.  </p>