Skip to content

Commit 5894079

Browse files
committed
Polish resilience features
1 parent 670effa commit 5894079

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

framework-docs/modules/ROOT/pages/core/resilience.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public void sendNotification() {
4040
NOTE: `@Retryable(MessageDeliveryException.class)` is a shortcut for
4141
`@Retryable(includes{nbsp}={nbsp}MessageDeliveryException.class)`.
4242

43+
[TIP]
44+
====
45+
For advanced use cases, you can specify a custom `MethodRetryPredicate` via the
46+
`predicate` attribute in `@Retryable`, and the predicate will be used to determine whether
47+
to retry a failed method invocation based on a `Method` and a given `Throwable` – for
48+
example, by checking the message of the `Throwable`.
49+
50+
Custom predicates can be combined with `includes` and `excludes`; however, custom
51+
predicates will always be applied after `includes` and `excludes` have been applied.
52+
====
53+
4354
Or for 5 retry attempts and an exponential back-off strategy with a bit of jitter:
4455

4556
[source,java,indent=0,subs="verbatim,quotes"]

spring-context/src/main/java/org/springframework/resilience/annotation/ConcurrencyLimitBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private class ConcurrencyLimitInterceptor implements MethodInterceptor {
8282
Object target = invocation.getThis();
8383
Class<?> targetClass = (target != null ? target.getClass() : method.getDeclaringClass());
8484
if (target == null && invocation instanceof ProxyMethodInvocation methodInvocation) {
85-
// Allow validation for AOP proxy without a target
85+
// Support concurrency throttling for AOP proxy without a target
8686
target = methodInvocation.getProxy();
8787
}
8888
Assert.state(target != null, "Target must not be null");

spring-context/src/main/java/org/springframework/resilience/annotation/Retryable.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
/**
6565
* Applicable exception types to attempt a retry for. This attribute
6666
* allows for the convenient specification of assignable exception types.
67+
* <p>This can optionally be combined with {@link #excludes() excludes} or
68+
* a custom {@link #predicate() predicate}.
6769
* <p>The default is empty, leading to a retry attempt for any exception.
6870
* @see #excludes()
6971
* @see #predicate()
@@ -74,19 +76,23 @@
7476
/**
7577
* Non-applicable exception types to avoid a retry for. This attribute
7678
* allows for the convenient specification of assignable exception types.
79+
* <p>This can optionally be combined with {@link #includes() includes} or
80+
* a custom {@link #predicate() predicate}.
7781
* <p>The default is empty, leading to a retry attempt for any exception.
7882
* @see #includes()
7983
* @see #predicate()
8084
*/
8185
Class<? extends Throwable>[] excludes() default {};
8286

8387
/**
84-
* A predicate for filtering applicable exceptions for which
85-
* an invocation can be retried.
86-
* <p>The default is a retry attempt for any exception.
88+
* A predicate for filtering applicable exceptions for which an invocation can
89+
* be retried.
8790
* <p>A specified {@link MethodRetryPredicate} implementation will be instantiated
8891
* per method. It can use dependency injection at the constructor level or through
8992
* autowiring annotations, in case it needs access to other beans or facilities.
93+
* <p>This can optionally be combined with {@link #includes() includes} or
94+
* {@link #excludes() excludes}.
95+
* <p>The default is a retry attempt for any exception.
9096
* @see #includes()
9197
* @see #excludes()
9298
*/

spring-core/src/main/java/org/springframework/core/retry/RetryPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ static RetryPolicy withDefaults() {
8080

8181
/**
8282
* Create a {@link RetryPolicy} configured with a maximum number of retry attempts.
83-
* <p>The returned policy uses a fixed backoff of {@value Builder#DEFAULT_DELAY}
84-
* milliseconds.
83+
* <p>The returned policy applies to all exception types and uses a fixed backoff
84+
* of {@value Builder#DEFAULT_DELAY} milliseconds.
8585
* @param maxAttempts the maximum number of retry attempts;
8686
* must be positive (or zero for no retry)
8787
* @see Builder#maxAttempts(long)

0 commit comments

Comments
 (0)