Annotation Interface Retryable
Aligned with RetryTemplate
as well as Reactor's retry support, either re-invoking an imperative
target method or decorating a reactive result accordingly.
Inspired by the Spring Retry project but redesigned as a minimal core retry feature in the Spring Framework.
- Since:
- 7.0
- Author:
- Juergen Hoeller
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionlong
The base delay after the initial invocation.The base delay after the initial invocation, as a duration String.Non-applicable exception types to avoid a retry for.Applicable exception types to attempt a retry for.long
A jitter value for the base retry attempt, randomly subtracted or added to the calculated delay, resulting in a value betweendelay - jitter
anddelay + jitter
but never below the basedelay()
or abovemaxDelay()
.A jitter value for the base retry attempt, as a duration String.long
The maximum number of retry attempts, in addition to the initial invocation.The maximum number of retry attempts, as a configurable String.long
The maximum delay for any retry attempt, limiting how farjitter()
andmultiplier()
can increase the delay.The maximum delay for any retry attempt, as a duration String.double
A multiplier for a delay for the next retry attempt, as a configurable String.Class
<? extends MethodRetryPredicate> A predicate for filtering applicable exceptions for which an invocation can be retried.TheTimeUnit
to use fordelay()
,delayString()
,jitter()
,jitterString()
,maxDelay()
, andmaxDelayString()
.Convenient default attribute forincludes()
, typically used with a single exception type to retry for.
-
Element Details
-
value
Convenient default attribute forincludes()
, typically used with a single exception type to retry for.- Default:
{}
-
includes
-
excludes
-
predicate
Class<? extends MethodRetryPredicate> predicateA predicate for filtering applicable exceptions for which an invocation can be retried.The default is a retry attempt for any exception.
A specified
MethodRetryPredicate
implementation will be instantiated per method. It can use dependency injection at the constructor level or through autowiring annotations, in case it needs access to other beans or facilities.- See Also:
- Default:
org.springframework.resilience.retry.MethodRetryPredicate.class
-
maxAttempts
long maxAttemptsThe maximum number of retry attempts, in addition to the initial invocation.The default is 3.
- Default:
3L
-
maxAttemptsString
String maxAttemptsStringThe maximum number of retry attempts, as a configurable String. A non-empty value specified here overrides themaxAttempts()
attribute.This supports Spring-style "${...}" placeholders as well as SpEL expressions.
- See Also:
- Default:
""
-
delay
long delayThe base delay after the initial invocation. If a multiplier is specified, this serves as the initial delay to multiply from.The time unit is milliseconds by default but can be overridden via
timeUnit()
.Must be greater than or equal to zero. The default is 1000.
- See Also:
- Default:
1000L
-
delayString
String delayStringThe base delay after the initial invocation, as a duration String. A non-empty value specified here overrides thedelay()
attribute.The duration String can be in several formats:
- a plain integer — which is interpreted to represent a duration in
milliseconds by default unless overridden via
timeUnit()
(prefer usingdelay()
in that case) - any of the known
DurationFormat.Style
: theISO8601
style or theSIMPLE
style — using thetimeUnit()
as fallback if the string doesn't contain an explicit unit - one of the above, with Spring-style "${...}" placeholders as well as SpEL expressions
- Returns:
- the initial delay as a String value — for example a placeholder,
or a
java.time.Duration
compliant value or asimple format
compliant value - See Also:
- Default:
""
- a plain integer — which is interpreted to represent a duration in
milliseconds by default unless overridden via
-
jitter
long jitterA jitter value for the base retry attempt, randomly subtracted or added to the calculated delay, resulting in a value betweendelay - jitter
anddelay + jitter
but never below the basedelay()
or abovemaxDelay()
. If a multiplier is specified, it is applied to the jitter value as well.The time unit is milliseconds by default but can be overridden via
timeUnit()
.The default is 0 (no jitter).
- See Also:
- Default:
0L
-
jitterString
String jitterStringA jitter value for the base retry attempt, as a duration String. A non-empty value specified here overrides thejitter()
attribute.The duration String can be in several formats:
- a plain integer — which is interpreted to represent a duration in
milliseconds by default unless overridden via
timeUnit()
(prefer usingjitter()
in that case) - any of the known
DurationFormat.Style
: theISO8601
style or theSIMPLE
style — using thetimeUnit()
as fallback if the string doesn't contain an explicit unit - one of the above, with Spring-style "${...}" placeholders as well as SpEL expressions
- Returns:
- the initial delay as a String value — for example a placeholder,
or a
java.time.Duration
compliant value or asimple format
compliant value - See Also:
- Default:
""
- a plain integer — which is interpreted to represent a duration in
milliseconds by default unless overridden via
-
multiplier
-
multiplierString
String multiplierStringA multiplier for a delay for the next retry attempt, as a configurable String. A non-empty value specified here overrides themultiplier()
attribute.This supports Spring-style "${...}" placeholders as well as SpEL expressions.
- See Also:
- Default:
""
-
maxDelay
long maxDelayThe maximum delay for any retry attempt, limiting how farjitter()
andmultiplier()
can increase the delay.The time unit is milliseconds by default but can be overridden via
timeUnit()
.The default is unlimited.
- See Also:
- Default:
9223372036854775807L
-
maxDelayString
String maxDelayStringThe maximum delay for any retry attempt, as a duration String. A non-empty value specified here overrides themaxDelay()
attribute.The duration String can be in several formats:
- a plain integer — which is interpreted to represent a duration in
milliseconds by default unless overridden via
timeUnit()
(prefer usingmaxDelay()
in that case) - any of the known
DurationFormat.Style
: theISO8601
style or theSIMPLE
style — using thetimeUnit()
as fallback if the string doesn't contain an explicit unit - one of the above, with Spring-style "${...}" placeholders as well as SpEL expressions
- Returns:
- the initial delay as a String value — for example a placeholder,
or a
java.time.Duration
compliant value or asimple format
compliant value - See Also:
- Default:
""
- a plain integer — which is interpreted to represent a duration in
milliseconds by default unless overridden via
-
timeUnit
TimeUnit timeUnitTheTimeUnit
to use fordelay()
,delayString()
,jitter()
,jitterString()
,maxDelay()
, andmaxDelayString()
.The default is
TimeUnit.MILLISECONDS
.This attribute is ignored for
Duration
values supplied viadelayString()
,jitterString()
, ormaxDelayString()
.- Returns:
- the
TimeUnit
to use
- Default:
MILLISECONDS
-