英文原文:Spring Cloud Gateway
目录
概述
该项目提供了一个用于在Spring MVC之上构建API网关的库。 Spring Cloud Gateway旨在提供一种简单而有效的方式来路由到API,并为他们提供横切关注点,例如:安全性,监控/指标和弹性。
特性
Spring Cloud Gateway功能:
- 基于Spring Framework 5,Project Reactor和Spring Boot 2.0构建
- 能够匹配任何请求属性上的路由。
- 谓词和过滤器特定于路线。
- Hystrix断路器集成。
- Spring Cloud DiscoveryClient集成
- 易于编写谓词和过滤器
- 请求率限制
- 路径重写
入门
@SpringBootApplication
public class DemogatewayApplication {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("path_route", r -> r.path("/get")
.uri("http://httpbin.org"))
.route("host_route", r -> r.host("*.myhost.org")
.uri("http://httpbin.org"))
.route("rewrite_route", r -> r.host("*.rewrite.org")
.filters(f -> f.rewritePath("/foo/(?<segment>.*)", "/${segment}"))
.uri("http://httpbin.org"))
.route("hystrix_route", r -> r.host("*.hystrix.org")
.filters(f -> f.hystrix(c -> c.setName("slowcmd")))
.uri("http://httpbin.org"))
.route("hystrix_fallback_route", r -> r.host("*.hystrixfallback.org")
.filters(f -> f.hystrix(c -> c.setName("slowcmd").setFallbackUri("forward:/hystrixfallback")))
.uri("http://httpbin.org"))
.route("limit_route", r -> r
.host("*.limited.org").and().path("/anything/**")
.filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter())))
.uri("http://httpbin.org"))
.build();
}
}
要运行您自己的网关,请使用spring-cloud-starter-gateway依赖项。
快速开始
使用Spring Initializr引导您的应用程序。
学习
文档
每个Spring项目都有自己的; 它详细解释了如何使用项目功能以及使用它们可以实现的功能。
2.1.0 RC3 PRE CURRENT | Reference Doc. | API Doc. |
2.0.3 SNAPSHOT CURRENT | Reference Doc. | API Doc. |
2.0.2 CURRENT GA | Reference Doc. | API Doc. |
1.0.3 SNAPSHOT CURRENT | Reference Doc. | API Doc. |
1.0.2 CURRENT GA | Reference Doc. | API Doc. |
指南
该指南旨在在15-30分钟内完成,提供快速,实用的说明,用于为Spring的任何开发任务构建入门应用程序。
- Building a Gateway 了解如何配置网关
示例
尝试一些例子:
- Spring Cloud Gateway Sample 样本包含在项目中并在每次CI运行期间进行测试。
- Spring Cloud Samples Gateway 外部样本显示更复杂的过滤器和谓词用法。