Skip to content

Commit 4266738

Browse files
committed
Adds retry.adoc retry filter docs
1 parent a5e16a6 commit 4266738

File tree

1 file changed

+43
-31
lines changed
  • docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters

1 file changed

+43
-31
lines changed

docs/modules/ROOT/pages/spring-cloud-gateway-server-mvc/filters/retry.adoc

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
The `Retry` filter supports the following parameters:
55

66
* `retries`: The number of retries that should be attempted.
7-
* `statuses`: The HTTP status codes that should be retried, represented by using `org.springframework.http.HttpStatus`.
7+
//TODO: implement statuses
8+
//* `statuses`: The HTTP status codes that should be retried, represented by using `org.springframework.http.HttpStatus`.
89
* `methods`: The HTTP methods that should be retried, represented by using `org.springframework.http.HttpMethod`.
910
* `series`: The series of status codes to be retried, represented by using `org.springframework.http.HttpStatus.Series`.
1011
* `exceptions`: A list of thrown exceptions that should be retried.
11-
* `backoff`: The configured exponential backoff for the retries.
12-
Retries are performed after a backoff interval of `firstBackoff * (factor ^ n)`, where `n` is the iteration.
13-
If `maxBackoff` is configured, the maximum backoff applied is limited to `maxBackoff`.
14-
If `basedOnPreviousValue` is true, the backoff is calculated by using `prevBackoff * factor`.
12+
//* `backoff`: The configured exponential backoff for the retries.
13+
//Retries are performed after a backoff interval of `firstBackoff * (factor ^ n)`, where `n` is the iteration.
14+
//If `maxBackoff` is configured, the maximum backoff applied is limited to `maxBackoff`.
15+
//If `basedOnPreviousValue` is true, the backoff is calculated by using `prevBackoff * factor`.
1516

1617
The following defaults are configured for `Retry` filter, if enabled:
1718

1819
* `retries`: Three times
1920
* `series`: 5XX series
2021
* `methods`: GET method
21-
* `exceptions`: `IOException` and `TimeoutException`
22-
* `backoff`: disabled
22+
* `exceptions`: `IOException`, `TimeoutException` and `RetryException`
23+
//* `backoff`: disabled
2324

2425
The following listing configures a Retry filter:
2526

@@ -29,29 +30,46 @@ The following listing configures a Retry filter:
2930
spring:
3031
cloud:
3132
gateway:
32-
routes:
33-
- id: retry_test
34-
uri: http://localhost:8080/flakey
35-
predicates:
36-
- Host=*.retry.com
37-
filters:
38-
- name: Retry
39-
args:
40-
retries: 3
41-
statuses: BAD_GATEWAY
42-
methods: GET,POST
43-
backoff:
44-
firstBackoff: 10ms
45-
maxBackoff: 50ms
46-
factor: 2
47-
basedOnPreviousValue: false
33+
mvc:
34+
routes:
35+
- id: retry_test
36+
uri: http://localhost:8080/flakey
37+
predicates:
38+
- Host=*.retry.com
39+
filters:
40+
- name: Retry
41+
args:
42+
retries: 3
43+
series: SERVER_ERROR
44+
methods: GET,POST
45+
----
46+
47+
.GatewaySampleApplication.java
48+
[source,java]
49+
----
50+
import static org.springframework.cloud.gateway.server.mvc.filter.RetryFilterFunctions.retry;
51+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
52+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
53+
import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.host;
54+
55+
@Configuration
56+
class RouteConfiguration {
57+
58+
@Bean
59+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
60+
return route("add_request_parameter_route")
61+
.route(host("*.retry.com"), http("https://example.org"))
62+
.filter(retry(config -> config.setRetries(3).setSeries(Set.of(HttpStatus.Series.SERVER_ERROR)).setMethods(Set.of(HttpMethod.GET, HttpMethod.POST))))
63+
.build();
64+
}
65+
}
4866
----
4967

5068
NOTE: When using the retry filter with a `forward:` prefixed URL, the target endpoint should be written carefully so that, in case of an error, it does not do anything that could result in a response being sent to the client and committed.
5169
For example, if the target endpoint is an annotated controller, the target controller method should not return `ResponseEntity` with an error status code.
5270
Instead, it should throw an `Exception` or signal an error (for example, through a `Mono.error(ex)` return value), which the retry filter can be configured to handle by retrying.
5371

54-
WARNING: When using the retry filter with any HTTP method with a body, the body will be cached and the gateway will become memory constrained. The body is cached in a request attribute defined by `ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR`. The type of the object is `org.springframework.core.io.buffer.DataBuffer`.
72+
// WARNING: When using the retry filter with any HTTP method with a body, the body will be cached and the gateway will become memory constrained. The body is cached in a request attribute defined by `ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR`. The type of the object is `org.springframework.core.io.buffer.DataBuffer`.
5573

5674
A simplified "shortcut" notation can be added with a single `status` and `method`.
5775

@@ -72,15 +90,9 @@ spring:
7290
retries: 3
7391
statuses: INTERNAL_SERVER_ERROR
7492
methods: GET
75-
backoff:
76-
firstBackoff: 10ms
77-
maxBackoff: 50ms
78-
factor: 2
79-
basedOnPreviousValue: false
80-
8193
- id: retryshortcut_route
8294
uri: https://example.org
8395
filters:
84-
- Retry=3,INTERNAL_SERVER_ERROR,GET,10ms,50ms,2,false
96+
- Retry=3,INTERNAL_SERVER_ERROR,GET
8597
----
8698

0 commit comments

Comments
 (0)