Skip to content

Commit c7e1d80

Browse files
committed
Updates sagan-index.adoc to reflect webflux and webmvc
1 parent 2554bbe commit c7e1d80

File tree

1 file changed

+72
-15
lines changed

1 file changed

+72
-15
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.

0 commit comments

Comments
 (0)