Search code examples
springapache-kafkakafka-consumer-apispring-kafka

How to do Stateful retry with spring kafka batch listener


I'm reading through the docs here https://docs.spring.io/spring-kafka/docs/2.2.6.RELEASE/reference/html/#retrying-deliveries and I cannot figure out what the correct way is for implementing stateful retry with a batch listener

The docs say that a "retry adapter is not provided for batch message listeners because the framework has no knowledge of where in a batch the failure occurred".

This is not a problem for my use case as I want to just retry the whole batch.

The docs recommend that I use a RetryTemplate within the listener itself. Ok, I can do that.

The problem comes in the next section where it discusses using the stateful retry flag to make the consumer poll between retries in order to prevent the broker from dropping my consumer.

How do I configure a batch listener to do that? Is the stateful retry flag supported for batch listeners? If My retry logic is in within the listener itself, wouldn't that prevent the polling? What exactly does the statefulRetry flag even do?


Solution

  • The latest version of spring kafka has a special RetryingBatchErrorHandler. https://docs.spring.io/spring-kafka/docs/2.4.6.RELEASE/reference/html/#retrying-batch-eh Thanks, Spring Kafka Team!