title: Error handling - Consumer - apache kafka and spring
body: <p>I am learning to use kafka, I have two services a producer and a consumer.</p>
  
  <p>The producer produces messages that require processing (queries to services and database). These messages are received by the consumer, it is responsible for processing them and saves the result in a database</p>
  
  <p>Producer</p>
  
  <pre><code>@Autowired
  private KafkaTemplate&lt;String, String&gt; kafkaTemplate;
  ...
  kafkaTemplate.send(topic, message);
  </code></pre>
  
  <p>Consumer</p>
  
  <pre><code>@KafkaListener(topics = "....")
  public void listen(@Payload String message) {
  ....
  }
  </code></pre>
  
  <p>I would like all messages to be processed correctly by the consumer.
  I do not know how to handle errors on the consumer side in this context. For example, a database might be temporarily disabled and could not handle certain messages.</p>
  
  <p>What to do in these cases?</p>
  
  <p>I know that the responsibility belongs to the consumer.
  I could do retries, but retry several times in a row if a database is down does not seem like a good idea. And if I continue to consume messages, the index advances and I lose the events that I could not process by mistake.</p>