'Kafka How to not move offset until message processing is succeeded

We are reading messages from a Kafka-topic. I was under the (false) impression that by setting the EnableAutoOffsetStore/enable.auto.offset.store = false you, as a consumer could choose when you wanted to move the offset.

We were using this like so

while (!cancellationToken.IsCancellationRequested)
{
    try{       
         var consumeResult = kafkaConsumer.Consume(cancellationToken);             
         // process consumeResult.Message
         kafkaConsumer.StoreOffset(consumeResult);
    }
    catch
    {
      // delay and re-try
    } 
}

In this way we could re-read the message if we got an exception. We have 1 producer, 1 consumer,1 topic, 1 partition (and 1 group)

How should this behavior be achieved?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source