Spring Cloud GatewaySpring Cloud Gateway4.2.1

该项目提供了一个基于 Spring WebFlux 构建 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

快速启动您的项目

更进一步

VMware 提供培训和认证,以加速您的进步。

了解更多

获取支持

Tanzu Spring 在一个简单的订阅中提供对 OpenJDK™、Spring 和 Apache Tomcat® 的支持和二进制文件。

了解更多

即将举行的活动

查看 Spring 社区中所有即将举行的活动。

查看全部