Replace Spring Retry usage to core retry #4059
Open
+1,419
−490
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit replaces Spring Retry by the core retry support introduced in Spring Framework 7. This is a breaking change mostly in configuration that is detailed below.
The main feature in Spring Kafka is BackOffValuesGenerator that generates the required BackOff values upfront. These are then managed by the listener infrastructure and Spring Retry is no longer involved.
Moving this code from BackOffPolicy to BackOff dramatically simplifies that class as Spring Framework's core API naturally provides this information without the need of an extra infrastructure.
From a configuration standpoint, Spring Kafka relies quite heavily on Spring Retry's
@Backoff
. As there is no equivalent, the annotation has been moved to Spring Kafka proper with the following improvements:@BackOff
instead of@Backoff
).java.util.Duration
format.The creation of a
BackOff
instance from the annotation is now isolated inBackOffFactory
and the relevant tests have been added.RetryTopicConfigurationBuilder
is mostly backward-compatible butuniformRandomBackoff
has been deprecated as we feel that its name does not convey what it actually does.RetryingDeserializer
no longer offer aRecoveryCallback
but an equivalent function that takesRetryException
as an input. This contains the exceptions thrown as well as the number of retry attempts.The use of BinaryExceptionClassifier has been replaced by the newly introduced
ExceptionMatcher
that is a copy of the original algorithm with a polished API.With the migration done, we believe that further improvements can be made here:
@BackOff
oddly looks like Spring Framework's@Retryable
. As a matter of a fact, themaxAttempts
andincludes
/excludes
from@RetryableTopic
are touching the same concepts. One option would be to open up@Retryable
so that it can be used in more case.Another area of improvement is that harmonization of BackOff as a term. It is named "Backoff" in several places, including in
@RetryableTopic
, and it would be nice if the concept had the same syntax everywhere.With Spring Retry being completely removed, this commit also removes the dependency and any further references to it.