Punter Vicky
Punter Vicky

Reputation: 17042

Spring Kafka Consumer Retry

I am using Spring Kafka consumer which fetches messages from a topic and persist them into a db. If a failure condition is met , say for instance the db is unavailable , does kafka consumer library provide mechanism to retry ? If it does , is there a way to set different retry intervals such as 1st retry should be done after 5 mins , 2nd after 30 mins , 3rd after 1 hr etc.

Upvotes: 13

Views: 23942

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121560

Spring Kafka is shipped with the RetryingMessageListenerAdapter and RetryingAcknowledgingMessageListenerAdapter. If you use @KafkaListener, you can supply AbstractKafkaListenerContainerFactory with the RetryTemplate. And the last one can be injected with any custom RetryPolicy and BackOffPolicy from the Spring Retry project:

https://docs.spring.io/spring-kafka/reference/html/#retrying-deliveries

Also bear in mind that since version 2.0, there is transaction support in Spring Kafka, based on such one in the Apache Kafka 0.11.x.x:

https://docs.spring.io/spring-kafka/reference/html/#transactions

Upvotes: 15

Related Questions