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 社群中所有即將舉行的活動。

檢視全部