Skip to content

Commit 3a4ca16

Browse files
committed
Provide wrapper around retry
1 parent de7acb8 commit 3a4ca16

File tree

14 files changed

+972
-317
lines changed

14 files changed

+972
-317
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
*** xref:spring-cloud-gateway-server-webmvc/filters/setstatus.adoc[]
107107
*** xref:spring-cloud-gateway-server-webmvc/filters/stripprefix.adoc[]
108108
*** xref:spring-cloud-gateway-server-webmvc/filters/retry.adoc[]
109-
*** xref:spring-cloud-gateway-server-webmvc/filters/framework-retry.adoc[]
110109
*** xref:spring-cloud-gateway-server-webmvc/filters/requestsize.adoc[]
111110
*** xref:spring-cloud-gateway-server-webmvc/filters/setrequesthostheader.adoc[]
112111
*** xref:spring-cloud-gateway-server-webmvc/filters/tokenrelay.adoc[]

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

Lines changed: 0 additions & 109 deletions
This file was deleted.

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
[[retry-filter]]
22
= `Retry` Filter
33

4-
WARNING: This filter is based upon https://github.com/spring-projects/spring-retry[Spring Retry] which has been placed in maintenance-only mode. If/when
5-
Spring Retry is no longer being maintained, this filter will be removed. You should instead xref:spring-cloud-gateway-server-webmvc/filters/framework-retry.adoc[use the new
6-
filter] based on the retry functionality in Spring Framework.
4+
The `Retry` filter automatically selects the appropriate retry implementation based on what is available on the classpath:
5+
6+
* If https://github.com/spring-projects/spring-retry[Spring Retry] is on the classpath, the filter uses `GatewayRetryFilterFunctions` (based on Spring Retry) by default.
7+
* If Spring Retry is not on the classpath, the filter automatically uses `FrameworkRetryFilterFunctions` (based on the retry functionality in https://docs.spring.io/spring-framework/reference/7.0-SNAPSHOT/core/resilience.html[Spring Framework 7]).
8+
9+
WARNING: Spring Retry has been placed in maintenance-only mode. Once Spring Retry is no longer being maintained, the `Retry` filter will exclusively use the Framework retry implementation (`FrameworkRetryFilterFunctions`), and the Spring Retry-based implementation will be removed.
10+
11+
TIP: You can force the use of the Framework retry filter even when Spring Retry is on the classpath by setting `spring.cloud.gateway.server.webmvc.use-framework-retry-filter=true` in your configuration.
712

813
The `Retry` filter supports the following parameters:
914

@@ -116,3 +121,24 @@ spring:
116121
- Retry=3,INTERNAL_SERVER_ERROR,GET
117122
----
118123

124+
== Forcing Framework Retry Filter
125+
126+
When Spring Retry is on the classpath, the `Retry` filter uses the Spring Retry-based implementation by default. To force the use of the Framework retry filter instead, set the following property:
127+
128+
.application.yml
129+
[source,yaml]
130+
----
131+
spring:
132+
cloud:
133+
gateway:
134+
server:
135+
webmvc:
136+
use-framework-retry-filter: true
137+
----
138+
139+
.application.properties
140+
[source,properties]
141+
----
142+
spring.cloud.gateway.server.webmvc.use-framework-retry-filter=true
143+
----
144+

spring-cloud-gateway-integration-tests/httpclient/src/main/java/org/springframework/cloud/gateway/tests/httpclient/HttpClientApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.prefixPath;
5050
import static org.springframework.cloud.gateway.server.mvc.filter.FrameworkRetryFilterFunctions.frameworkRetry;
51+
import static org.springframework.cloud.gateway.server.mvc.filter.GatewayRetryFilterFunctions.retry;
5152
import static org.springframework.cloud.gateway.server.mvc.filter.LoadBalancerFilterFunctions.lb;
52-
import static org.springframework.cloud.gateway.server.mvc.filter.RetryFilterFunctions.retry;
5353
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
5454
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
5555

spring-cloud-gateway-server-webmvc/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<optional>true</optional>
9999
</dependency>
100100
<!-- Spring test dependencies -->
101+
<dependency>
102+
<groupId>org.springframework.cloud</groupId>
103+
<artifactId>spring-cloud-test-support</artifactId>
104+
<scope>test</scope>
105+
</dependency>
101106
<dependency>
102107
<groupId>org.springframework.boot</groupId>
103108
<artifactId>spring-boot-starter-test</artifactId>

spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/config/GatewayMvcProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public class GatewayMvcProperties {
6868
*/
6969
private String trustedProxies;
7070

71+
/**
72+
* In the case where Spring Retry is on the classpath but you still want to use Spring
73+
* Framework retry as your retry filter, set this property to true.
74+
*/
75+
private boolean useFrameworkRetryFilter = false;
76+
7177
public List<RouteProperties> getRoutes() {
7278
return routes;
7379
}
@@ -92,6 +98,14 @@ public void setStreamingMediaTypes(List<MediaType> streamingMediaTypes) {
9298
this.streamingMediaTypes = streamingMediaTypes;
9399
}
94100

101+
public boolean isUseFrameworkRetryFilter() {
102+
return useFrameworkRetryFilter;
103+
}
104+
105+
public void setUseFrameworkRetryFilter(boolean useFrameworkRetryFilter) {
106+
this.useFrameworkRetryFilter = useFrameworkRetryFilter;
107+
}
108+
95109
public int getStreamingBufferSize() {
96110
return streamingBufferSize;
97111
}

spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/FilterAutoConfiguration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
import org.springframework.boot.autoconfigure.AutoConfiguration;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2727
import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
28+
import org.springframework.cloud.gateway.server.mvc.config.GatewayMvcProperties;
2829
import org.springframework.cloud.gateway.server.mvc.config.RouteProperties;
2930
import org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctionDefinition;
3031
import org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions;
3132
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
34-
import org.springframework.retry.support.RetryTemplate;
3535
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
3636

3737
@AutoConfiguration
@@ -83,11 +83,17 @@ public Function<RouteProperties, HandlerFunctionDefinition> lbHandlerFunctionDef
8383
}
8484

8585
@Configuration(proxyBeanMethods = false)
86-
@ConditionalOnClass(RetryTemplate.class)
8786
static class RetryFilterConfiguration {
8887

88+
private final GatewayMvcProperties properties;
89+
90+
RetryFilterConfiguration(GatewayMvcProperties properties) {
91+
this.properties = properties;
92+
}
93+
8994
@Bean
9095
public RetryFilterFunctions.FilterSupplier retryFilterFunctionsSupplier() {
96+
RetryFilterFunctions.setUseFrameworkRetry(properties.isUseFrameworkRetryFilter());
9197
return new RetryFilterFunctions.FilterSupplier();
9298
}
9399

0 commit comments

Comments
 (0)