Spring Cloud Gateway 2.2.2

This project provides a library for building an API Gateway on top of Spring MVC. 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.
Features

Spring Cloud Gateway features:

Built on Spring Framework 5, Project Reactor and Spring Boot 2.0

Able to match routes on any request attribute.

Predicates and filters are specific to routes.

Hystrix Circuit Breaker integration.

Spring Cloud DiscoveryClient integration

Easy to write Predicates and Filters

Request Rate Limiting

Path Rewriting

Getting Started

@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}”))
.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();
}
}

To run your own gateway use the spring-cloud-starter-gateway dependency.
Quick start
Bootstrap your application with Spring Initializr.

发布了0 篇原创文章 · 获赞 0 · 访问量 1533

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/104718831