Search code examples
spring-bootspring-cloudkafka-consumer-apiapache-kafka-streams

Spring cloud kafka stream consumer retry mechanism


What is the meaning of the properties below and how do I use them?

spring.cloud.stream.bindings.atcommnity.consumer.maxAttempts=5
spring.cloud.stream.bindings.atcommnity.consumer.backOffInitialInterval=1000
spring.cloud.stream.bindings.atcommnity.consumer.backOffMaxInterval=2000000
spring.cloud.stream.bindings.atcommnity.consumer.backOffMultiplier=2.0
spring.cloud.stream.bindings.atcommnity.consumer.batch-mode=false

Solution

  • The backoff will start with backOffInitialInterval and then every next attempt will be multiplied by backOffMultiplier but will not exceed backOffMaxInterval.

    currentInterval = Math.min(backOffInitialInterval * Math.pow(backOffMultiplier, retryNum), backOffMaxInterval)

    In your case it will be:

    1000ms -> 2000ms -> 4000ms -> 8000ms -> 16000ms