-
Notifications
You must be signed in to change notification settings - Fork 633
Description
Problem
Currently we have consumers which have been configured with a default value for max attempts:
spring.cloud.stream.default.consumer.maxAttempts=2.
With Spring Boot 3, the configuration matched our desired behaviour, which was that an event would be consumed a maximum of 2 times in case of an error.
After the migration to Spring Boot 4 we now observe that the event is consumed 3 times in the event of an error. We tested other values with the configuration and it seems as if it is now always +1 attempt. So if we set the value to 5, there are 6 attempts.
Research
It seems that there is an issue with the org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder which only builds a RetryTemplate when the configured value for maxAttempts > 1.
This creates a RetryPolicy which documentation says following for the value of maxRetries:
Note that total attempts = 1 initial attempt + maxRetries attempts. Thus, if maxRetries is set to 4, a retryable operation will be invoked at least once and at most 5 times.
Impact
It looks like 2 attempts are no longer possible. Either a retry is directly prevented (no creation of RetryTemplate) or the number of retries is at least 3.
Environment
- Spring Cloud Stream: 5.0.1
- Spring Boot: 4.0.3