Browse Source

Add documentation. Reformat.

pull/1085/head
Olga Maciaszek-Sharma 3 years ago
parent
commit
ca813ec0d3
  1. 6
      docs/src/main/asciidoc/spring-cloud-commons.adoc
  2. 1
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRetryPolicy.java
  3. 10
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/RetryableLoadBalancerExchangeFilterFunctionTests.java

6
docs/src/main/asciidoc/spring-cloud-commons.adoc

@ -464,10 +464,14 @@ You can set:
For the reactive implementation, you can additionally 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.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.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 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.<clientId>.*` where `clientId` is the name of the loadbalancer. NOTE: Individual Loadbalancer clients may be configured individually with the same properties as above except the prefix is `spring.cloud.loadbalancer.clients.<clientId>.*` 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`. 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`.

1
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}. * Retry logic to use for the {@link LoadBalancerClient}.
* *
* @author Ryan Baxter * @author Ryan Baxter
* @author Olga Maciaszek-Sharma
*/ */
public interface LoadBalancedRetryPolicy { public interface LoadBalancedRetryPolicy {

10
spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/reactive/RetryableLoadBalancerExchangeFilterFunctionTests.java

@ -180,8 +180,7 @@ class RetryableLoadBalancerExchangeFilterFunctionTests {
@Test @Test
void shouldRetryOnConfiguredException() { void shouldRetryOnConfiguredException() {
properties.getRetry() properties.getRetry().setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class)));
.setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class)));
when(clientRequest.method()).thenReturn(HttpMethod.GET); when(clientRequest.method()).thenReturn(HttpMethod.GET);
when(next.exchange(any())).thenThrow(new TestException()); when(next.exchange(any())).thenThrow(new TestException());
@ -195,8 +194,7 @@ class RetryableLoadBalancerExchangeFilterFunctionTests {
@Test @Test
void shouldRetryOnRetryableStatusCodeExceptionEvenWhenCustomExceptionsConfigured() { void shouldRetryOnRetryableStatusCodeExceptionEvenWhenCustomExceptionsConfigured() {
properties.getRetry() properties.getRetry().setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class)));
.setRetryableExceptions(new HashSet<>(Collections.singletonList(TestException.class)));
when(clientRequest.method()).thenReturn(HttpMethod.GET); when(clientRequest.method()).thenReturn(HttpMethod.GET);
when(next.exchange(any())).thenThrow(new RetryableStatusCodeException()); when(next.exchange(any())).thenThrow(new RetryableStatusCodeException());
@ -208,6 +206,8 @@ class RetryableLoadBalancerExchangeFilterFunctionTests {
inOrder.verify(next, times(2)).exchange(any()); inOrder.verify(next, times(2)).exchange(any());
} }
protected static class TestException extends RuntimeException { } protected static class TestException extends RuntimeException {
}
} }

Loading…
Cancel
Save