From ca813ec0d3df896c71306f2fd8051d83208d45ee Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Thu, 24 Mar 2022 15:40:58 +0100 Subject: [PATCH] Add documentation. Reformat. --- docs/src/main/asciidoc/spring-cloud-commons.adoc | 6 +++++- .../client/loadbalancer/LoadBalancedRetryPolicy.java | 1 + ...tryableLoadBalancerExchangeFilterFunctionTests.java | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-commons.adoc b/docs/src/main/asciidoc/spring-cloud-commons.adoc index 3927cae0..90dd22f1 100644 --- a/docs/src/main/asciidoc/spring-cloud-commons.adoc +++ b/docs/src/main/asciidoc/spring-cloud-commons.adoc @@ -464,10 +464,14 @@ You can set: For the reactive implementation, you can additionally set: - `spring.cloud.loadbalancer.retry.backoff.minBackoff` - Sets the minimum backoff duration (by default, 5 milliseconds) - `spring.cloud.loadbalancer.retry.backoff.maxBackoff` - Sets the maximum backoff duration (by default, max long value of milliseconds) - - `spring.cloud.loadbalancer.retry.backoff.jitter` - Sets the jitter used for calculationg the actual backoff duration for each call (by default, 0.5). + - `spring.cloud.loadbalancer.retry.backoff.jitter` - Sets the jitter used for calculating the actual backoff duration for each call (by default, 0.5). For the reactive implementation, you can also implement your own `LoadBalancerRetryPolicy` to have more detailed control over the load-balanced call retries. +For both implementations, you can also set the exceptions that will trigger the replies by adding a list of values under the `spring.cloud.loadbalancer.[serviceId].retry.retryable-exceptions` property. If you do, we'll make sure to add `RetryableStatusCodeExceptions` to the list of exceptions provided by you, so that we also retry on retryable status codes. If you do not specify any exceptions via properties, the exceptions we'll use by default are `IOException`, `TimeoutException` and `RetryableStatusCodeException`. You can also enable retrying on all exceptions by setting `spring.cloud.loadbalancer.[serviceId].retry.retry-on-all-exceptions` to `true`. + +WARNING: If you are using the blocking implementation with Spring Retries, if you want to keep the behaviour from previous releases, make sure to set `spring.cloud.loadbalancer.[serviceId].retry.retry-on-all-exceptions` to `true` as that used to be the default mode for the blocking implementation. + NOTE: Individual Loadbalancer clients may be configured individually with the same properties as above except the prefix is `spring.cloud.loadbalancer.clients..*` where `clientId` is the name of the loadbalancer. NOTE: For load-balanced retries, by default, we wrap the `ServiceInstanceListSupplier` bean with `RetryAwareServiceInstanceListSupplier` to select a different instance from the one previously chosen, if available. You can disable this behavior by setting the value of `spring.cloud.loadbalancer.retry.avoidPreviousInstance` to `false`. diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRetryPolicy.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRetryPolicy.java index 49ff6c2a..0d214d61 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRetryPolicy.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRetryPolicy.java @@ -20,6 +20,7 @@ package org.springframework.cloud.client.loadbalancer; * Retry logic to use for the {@link LoadBalancerClient}. * * @author Ryan Baxter + * @author Olga Maciaszek-Sharma */ public interface LoadBalancedRetryPolicy { diff --git a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/RetryableLoadBalancerExchangeFilterFunctionTests.java b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/RetryableLoadBalancerExchangeFilterFunctionTests.java index 628007c2..475aa397 100644 --- a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/RetryableLoadBalancerExchangeFilterFunctionTests.java +++ b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/RetryableLoadBalancerExchangeFilterFunctionTests.java @@ -180,8 +180,7 @@ class RetryableLoadBalancerExchangeFilterFunctionTests { @Test void shouldRetryOnConfiguredException() { - properties.getRetry() - .setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class))); + properties.getRetry().setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class))); when(clientRequest.method()).thenReturn(HttpMethod.GET); when(next.exchange(any())).thenThrow(new TestException()); @@ -195,8 +194,7 @@ class RetryableLoadBalancerExchangeFilterFunctionTests { @Test void shouldRetryOnRetryableStatusCodeExceptionEvenWhenCustomExceptionsConfigured() { - properties.getRetry() - .setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class))); + properties.getRetry().setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class))); when(clientRequest.method()).thenReturn(HttpMethod.GET); when(next.exchange(any())).thenThrow(new RetryableStatusCodeException()); @@ -208,6 +206,8 @@ class RetryableLoadBalancerExchangeFilterFunctionTests { inOrder.verify(next, times(2)).exchange(any()); } - protected static class TestException extends RuntimeException { } + protected static class TestException extends RuntimeException { + + } }