Spring Cloud Gateway

目录

  • 专业术语
  • 网关是如何工作的

Spring Cloud Gateway是一个基于Spring Framework的开源网关解决方案,用于构建微服务架构中的API网关。它提供了一种简单而有效的方式来路由、过滤和转换传入的请求,以实现对微服务的访问控制、负载均衡、认证授权、限流、监控等功能。

Spring Cloud Gateway建立在Spring生态系统之上,利用Spring的强大功能和特性,如反应式编程模型、异步和非阻塞I/O等,以实现高性能和可扩展性。

Spring Cloud Gateway的主要特点包括:

动态路由:可以根据请求的路径、参数、标头等条件来进行灵活的路由配置,动态地将请求路由到不同的后端服务。

过滤器:提供了丰富的过滤器机制,可以在请求转发前后进行各种操作,如鉴权、请求转换、请求日志记录等。

负载均衡:支持多种负载均衡策略,可以将请求均衡地分发到多个后端服务实例上。

容错机制:在后端服务不可用或出现故障时,提供了故障转移和熔断的机制,保证系统的可靠性和稳定性。

安全性:集成了Spring Security,可以进行认证和授权的配置,保护API网关和后端服务的安全性。

监控和指标:通过整合Spring Boot Actuator,可以获取关于网关的各种指标和监控信息,方便进行性能分析和故障排查。

Spring Cloud Gateway的设计目标是轻量级、灵活且易于扩展,它与Spring Cloud生态系统中的其他组件(如服务注册与发现、配置中心等)无缝集成,为构建微服务架构中的API网关提供了一种强大的解决方案。

专业术语

  • Route: 路由是网关的基本概念。他由ID、目的URI、一组谓词和一组过滤器构成。如果组合谓词为真,那么路由匹配了。

  • 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.

  • 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_第1张图片
Clients make requests to Spring Cloud Gateway. If the Gateway Handler Mapping determines that a request matches a route, it is sent to the Gateway Web Handler. This handler runs the request through a filter chain that is specific to the request. The reason the filters are divided by the dotted line is that filters can run logic both before and after the proxy request is sent. All “pre” filter logic is executed. Then the proxy request is made. After the proxy request is made, the “post” filter logic is run.
客户端向网关发起请求。如果请求匹配到一个路由,那么请求会被发送到Gateway Web Handler。该Handler会将该请求对应的过滤器应用到该请求。

你可能感兴趣的:(spring,gateway)