Description
This is a proposal for enabling auto configuration for the delayed non-blocking retries using topics feature that we introduced earlier this year on Spring for Apache Kafka 2.7.0.
More details on the feature can be found in the documentation: https://docs.spring.io/spring-kafka/docs/current/reference/html/#retry-topic
I already have a working draft with tests and should open a PR shortly so we can discuss it in more details if necessary.
The minimal configuration would be as simple as adding spring.kafka.retry-topic-enabled=true
to the application yaml or properties configurations file, which would apply a default global retry configuration to all topics.
spring:
kafka:
retry-topic-enabled: true
With that minimal configuration, the framework would set up topics and consumers with the following defaults:
- Retries for all topics
- 3 processing attempts before sending the message to the DLT
- FixedBackOffPolicy of 1 second between attempts
- Default topic suffixes of "-retry-1", "-retry-2", "-dlt"
- Create the retry topics and dlts automatically via NewTopic instances
- Retry on all exceptions
- Use a dedicated default ConcurrentKafkaListenerContainerFactory instance provided by the auto configuration specifically for creating the retry topics and dlt consumers
- Use the default Spring Kafka's KafkaTemplate from auto configuration for forwarding the messages to the topics
More specific configurations could also be provided in the configuration files, such as:
spring:
kafka:
retry-topic-enabled: true
retry-topic:
myGlobalConfiguration:
attempts: 4
back-off:
delay: 300s
multiplier: 2
max-delay: 1200s
topic-suffixing-strategy: suffix-with-index-value
dlt-strategy: fail-on-error
Optionally, more than one configuration could be provided for more fine-grained control over the configuration:
spring:
kafka:
retry-topic-enabled: true
retry-topic:
myGlobalConfiguration:
attempts: 4
back-off:
delay: 300s
multiplier: 2
max-delay: 1200s
topic-suffixing-strategy: suffix-with-index-value
dlt-strategy: fail-on-error
exclude-topics: my-specific-topic
mySpecificConfiguration:
include-topics: my-specific-topic
attempts: 5
back-off:
delay: 5s
not-retry-on:
- com.mycompany.myproject.mypackage.exceptions.MyException
- com.mycompany.myproject.mypackage.exceptions.MyOtherException
topic-suffixing-strategy: suffix-with-index-value
dlt-strategy: fail-on-error
Note: If it gets too verbose for many topic configurations the user should be able to provide that in one or more separate configuration files using standard spring boot configuration features such as spring.config.import
.
I'd appreciate any feedback you may have on this. Also please let me know if there are any questions or anything I can help with.
@garyrussell and @artembilan, I'd much appreciate your feedback too if and when possible.
Thank you all for the hard work you put into the awesome Spring projects!