Skip to content

Commit 94a5c75

Browse files
committed
Merge branch '4.2.x' into 4.3.x
2 parents 06a85ce + c7e1d80 commit 94a5c75

File tree

4 files changed

+108
-20
lines changed

4 files changed

+108
-20
lines changed
Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
This project provides a library for building an API Gateway on top of Spring WebFlux. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.
1+
---
2+
title: Spring Cloud Gateway
3+
status: ACTIVE
4+
stackOverflow: https://stackoverflow.com/questions/tagged/spring-cloud
5+
github: https://github.com/spring-cloud/spring-cloud-gateway
6+
site: https://spring.io/projects/spring-cloud-gateway
7+
order: 255
8+
supportPolicy: DOWNSTREAM
9+
parent: spring-cloud
10+
---
11+
12+
This project provides a library for building an API Gateway on top of Spring. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross-cutting concerns to them such as: security, monitoring/metrics, and resiliency.
213

314
## Features
415

516
Spring Cloud Gateway features:
617

7-
* Built on Spring Framework 5, Project Reactor and Spring Boot 2.0
18+
* Built on Spring Framework and Spring Boot
19+
* Compatible with both Spring WebFlux and Spring Web MVC
820
* Able to match routes on any request attribute.
921
* Predicates and filters are specific to routes.
10-
* Hystrix Circuit Breaker integration.
22+
* Spring Cloud Circuit Breaker integration.
1123
* Spring Cloud DiscoveryClient integration
1224
* Easy to write Predicates and Filters
1325
* Request Rate Limiting
1426
* Path Rewriting
1527

16-
## Getting Started
28+
## Getting Started with Spring Cloud Gateway Server WebFlux
1729

1830
```java
1931
@SpringBootApplication
@@ -22,25 +34,70 @@ public class DemogatewayApplication {
2234
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
2335
return builder.routes()
2436
.route("path_route", r -> r.path("/get")
25-
.uri("http://httpbin.org"))
37+
.uri("https://httpbin.org"))
2638
.route("host_route", r -> r.host("*.myhost.org")
27-
.uri("http://httpbin.org"))
39+
.uri("https://httpbin.org"))
2840
.route("rewrite_route", r -> r.host("*.rewrite.org")
2941
.filters(f -> f.rewritePath("/foo/(?<segment>.*)", "/${segment}"))
30-
.uri("http://httpbin.org"))
31-
.route("hystrix_route", r -> r.host("*.hystrix.org")
32-
.filters(f -> f.hystrix(c -> c.setName("slowcmd")))
33-
.uri("http://httpbin.org"))
34-
.route("hystrix_fallback_route", r -> r.host("*.hystrixfallback.org")
35-
.filters(f -> f.hystrix(c -> c.setName("slowcmd").setFallbackUri("forward:/hystrixfallback")))
36-
.uri("http://httpbin.org"))
42+
.uri("https://httpbin.org"))
43+
.route("circuit_breaker_route", r -> r.host("*.circuitbreaker.org")
44+
.filters(f -> f.circuitBreaker(c -> c.setName("slowcmd")))
45+
.uri("https://httpbin.org"))
46+
.route("circuit_breaker_fallback_route", r -> r.host("*.circuitbreakerfallback.org")
47+
.filters(f -> f.circuitBreaker(c -> c.setName("slowcmd").setFallbackUri("forward:/circuitbrekerfallback")))
48+
.uri("https://httpbin.org"))
3749
.route("limit_route", r -> r
3850
.host("*.limited.org").and().path("/anything/**")
3951
.filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter())))
40-
.uri("http://httpbin.org"))
52+
.uri("https://httpbin.org"))
4153
.build();
4254
}
4355
}
4456
```
4557

46-
To run your own gateway use the `spring-cloud-starter-gateway` dependency.
58+
To run your own Gateway Server WebFlux use the `spring-cloud-starter-gateway` dependency.
59+
60+
## Getting Started with Spring Cloud Gateway Server Web MVC
61+
62+
```java
63+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
64+
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.*;
65+
import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.*;
66+
67+
//...
68+
69+
@SpringBootApplication
70+
public class DemogatewayApplication {
71+
@Bean
72+
public RouterFunction<ServerResponse> customRoutes() {
73+
// @formatter:off
74+
return route("path_route")
75+
.GET("/get", http())
76+
.before(uri("https://httpbin.orb"))
77+
.build().and(route("host_route")
78+
.route(host("*.myhost.org"), http())
79+
.before(uri("https://httpbin.orb"))
80+
.build().and(route("rewrite_route")
81+
.route(host("*.rewrite.org"), http())
82+
.before(uri("https://httpbin.orb"))
83+
.before(rewritePath("/foo/(?<segment>.*)", "/${segment}"))
84+
.build().and(route("circuitbreaker_route")
85+
.route(host("*.circuitbreaker.org"), http())
86+
.before(uri("https://httpbin.orb"))
87+
.filter(circuitBreaker("slowcmd"))
88+
.build().and(route("circuitbreaker_fallback_route")
89+
.route(host("*.circuitbreakerfallback.org"), http())
90+
.before(uri("https://httpbin.orb"))
91+
.filter(circuitBreaker(c -> c.setId("slowcmd").setFallbackUri("forward:/fallback")))
92+
.build().and(route("limit_route")
93+
.route(host("*.limited.org").and(path("/anything/**")), http())
94+
.before(uri("https://httpbin.orb"))
95+
.filter(rateLimit(c -> c.setCapacity(10).setPeriod(Duration.ofSeconds(1)).setKeyResolver(request ->
96+
request.headers().firstHeader("X-TokenId"))))
97+
.build())))));
98+
// @formatter:on
99+
}
100+
}
101+
```
102+
103+
To run your own Gateway Server WebMVC use the `spring-cloud-starter-gateway-mvc` dependency.

pom.xml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<name>Spring Cloud Gateway</name>
1313
<description>Spring Cloud Gateway</description>
14+
<url>https://github.com/spring-cloud/spring-cloud-gateway</url>
1415

1516
<parent>
1617
<groupId>org.springframework.cloud</groupId>
@@ -39,11 +40,21 @@
3940
<developer>
4041
<id>sgibb</id>
4142
<name>Spencer Gibb</name>
42-
<email>sgibb at pivotal.io</email>
43-
<organization>Pivotal Software, Inc.</organization>
43+
<email>spencer.gibb at broadcom.com</email>
44+
<organization>Broadcom, Inc.</organization>
4445
<organizationUrl>https://www.spring.io</organizationUrl>
4546
<roles>
46-
<role>Project lead</role>
47+
<role>lead</role>
48+
</roles>
49+
</developer>
50+
<developer>
51+
<id>rbaxter</id>
52+
<name>Ryan Baxter</name>
53+
<email>ryan.baxter at broadcom.com</email>
54+
<organization>Broadcom, Inc.</organization>
55+
<organizationUrl>https://www.spring.io</organizationUrl>
56+
<roles>
57+
<role>developer</role>
4758
</roles>
4859
</developer>
4960
</developers>
@@ -184,6 +195,23 @@
184195
</build>
185196

186197
<profiles>
198+
<profile>
199+
<id>central</id>
200+
<build>
201+
<plugins>
202+
<plugin>
203+
<groupId>org.sonatype.central</groupId>
204+
<artifactId>central-publishing-maven-plugin</artifactId>
205+
<configuration>
206+
<excludeArtifacts>
207+
<artifact>spring-cloud-gateway-integration-tests</artifact>
208+
<artifact>spring-cloud-gateway-sample</artifact>
209+
</excludeArtifacts>
210+
</configuration>
211+
</plugin>
212+
</plugins>
213+
</build>
214+
</profile>
187215
<profile>
188216
<id>spring</id>
189217
<repositories>

spring-cloud-gateway-integration-tests/grpc/src/test/java/org/springframework/cloud/gateway/tests/grpc/JsonToGrpcApplicationTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.hc.core5.ssl.TrustStrategy;
3737
import org.assertj.core.api.Assertions;
3838
import org.junit.jupiter.api.BeforeEach;
39-
import org.junit.jupiter.api.Disabled;
4039
import org.junit.jupiter.api.Test;
4140

4241
import org.springframework.boot.test.context.SpringBootTest;
@@ -50,7 +49,6 @@
5049
* @author Alberto C. Ríos
5150
* @author Abel Salgado Romero
5251
*/
53-
@Disabled
5452
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
5553
public class JsonToGrpcApplicationTests {
5654

spring-cloud-gateway-mvc/src/test/java/org/springframework/cloud/gateway/mvc/ProductionConfigurationTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2626
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Disabled;
2728
import org.junit.jupiter.api.Test;
2829
import org.junit.jupiter.api.extension.ExtendWith;
2930

@@ -260,6 +261,10 @@ public void deleteWithoutBody() {
260261
assertThat(deleteResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
261262
}
262263

264+
@Disabled
265+
// TODO This is broken due to a regression in Spring Framework 6.2.8,
266+
// It will be fixed in 6.2.9 and boot 3.4.8
267+
// See https://github.com/spring-projects/spring-framework/issues/35068
263268
@Test
264269
public void deleteWithBody() {
265270
Foo foo = new Foo("to-be-deleted");

0 commit comments

Comments
 (0)