Spring Cloud Gateway4.1.5

此專案提供用於在 Spring WebFlux 或 Spring WebMVC 之上建構 API 閘道器的程式庫。Spring Cloud Gateway 旨在提供一種簡單而有效的方式來路由至 API,並為它們提供跨領域的關注點,例如:安全性、監控/指標和彈性。

功能

Spring Cloud Gateway 功能

  • 建構於 Spring Framework 和 Spring Boot 之上

  • 能夠比對任何請求屬性上的路由。

  • 述詞和篩選器特定於路由。

  • 斷路器整合。

  • 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 社群中所有即將到來的活動。

檢視全部