简介

网关作为流量入口,常用功能包括路由转发、权限校验、限流控制等.而SpringCloud GateWay作为SpringCloud官方推出的第二代网关框架,取代了Zuul网关.

三大概念

  1. Route(路由): The basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates断言, and a collection of filters. A route is matched if the aggregate predicate is true.发一个请求给网关,网关要将请求路由到指定的服务。路由有id,目的地uri,断言的集合,匹配了断言就能到达指定位置,
  2. Predicate(断言): This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This lets you match on anything from the HTTP request, such as headers or parameters.就是java里的断言函数,匹配请求里的任何信息,包括请求头等。根据请求头路由哪个服务
  3. Filter(过滤器): These are instances of Spring Framework GatewayFilter that have been constructed with a specific factory. Here, you can modify requests and responses before or after sending the downstream request.过滤器请求和响应都可以被修改。

spring_cloud_gateway_diagram

当一个请求到达 网关 网关利用断言判定请求是否符合某个路由规则,如果符合就按照路由规则路由到指定地方

要到达指定地方,就要经过一系列过滤器.

参考

官网: SpringCloudGateWay