Spring Cloud Gateway自动配置类解读

Spring Cloud Gateway自动配置类解读

  • 1. SpringCloudGateway最佳学习路径
  • 2. Spring WebFluxAutoConfiguration
  • 3. Spring WebFlux和Spring Boot Gateway融合
  • 4. BeanDefintions in GatewayAutoConfiguration
  • 5. Enviroment属性优先级
  • 6. ApplicationContext更新
  • 参考

1. SpringCloudGateway最佳学习路径

Reactive Streams -> Reactor -> Spring WebFlux -> Spring Boot - > Spring Cloud -> Spring Cloud Gateway
规范 -> 实现 -> 框架 -> Spring Boot -> Spring Cloud -> Spring Cloud Gateway

2. Spring WebFluxAutoConfiguration

GatewayLoadBalancerClientAutoConfiguration -> GatewayClassPathWarningAutoConfiguration -> GatewayAutoConfiguration -> WebFluxAutoConfiguration -> HttpHandlerAutoConfiguration

3. Spring WebFlux和Spring Boot Gateway融合

Flux Web Filter : WeightCalculatorWebFilter
Flux HandlerMapping : RoutePredicateHandlerMapping

4. BeanDefintions in GatewayAutoConfiguration

Properties
HttpClientProperties
GlobalCorsProperties
GatewayProperties
SecureHeadersProperties

Basic Configuration
HttpClient
WebSocketService
ReactorNettyWebSocketClient
GatewayControllerEndpoint
PrincipalNameKeyResolver
StringToZonedDateTimeConverter

WebFilter
WeightCalculatorWebFilter

HandlerMapping
RoutePredicateHandlerMapping
FilteringWebHandler -> SimpleHandlerAdaptor support

Route Related
RouteLocatorBuilder
PropertiesRouteDefinitionLocator
InMemoryRouteDefinitionRepository
RouteDefinitionLocator
RouteDefinitionRouteLocator
CachingRouteLocator @Primary
RouteRefreshListener

HttpHeadersFilter
ForwardedHeadersFilter
RemoveHopByHopHeadersFilter
XForwardedHeadersFilter

GlobalFilter

Filter Priority
RemoveCachedBodyFilter Ordered.HIGHEST_PRECEDENCE
AdaptCachedBodyGlobalFilter Ordered.HIGHEST_PRECEDENCE + 1000
NettyWriteResponseFilter -1
ForwardPathFilter 0
RouteToRequestUrlFilter 10000
GatewayNoLoadBalancerClientAutoConfiguration$NoLoadBalancerClientFilter 10100
WebsocketRoutingFilter Ordered.LOWEST_PRECEDENCE - 1
NettyRoutingFilter Ordered.LOWEST_PRECEDENCE
ForwardRoutingFilter Ordered.LOWEST_PRECEDENCE

RoutePredicateFactory
AfterRoutePredicateFactory
BeforeRoutePredicateFactory
BetweenRoutePredicateFactory
CookieRoutePredicateFactory
HeaderRoutePredicateFactory
HostRoutePredicateFactory
MethodRoutePredicateFactory
PathRoutePredicateFactory
QueryRoutePredicateFactory
ReadBodyPredicateFactory
RemoteAddrRoutePredicateFactory
WeightRoutePredicateFactory
CloudFoundryRouteServiceRoutePredicateFactory

GatewayFilterFactory

GatewayFilterFactory Description
AddRequestHeaderGatewayFilterFactory 往ServerHttpRequest添加表头信息
SetRequestHeaderGatewayFilterFactory 设置ServerHttpRequest的表头信息
RemoveRequestHeaderGatewayFilterFactory 从ServerHttpRequest中移除表头信息
SecureHeadersGatewayFilterFactory 添加安全相关的表头信息
AddResponseHeaderGatewayFilterFactory 往ServerHttpResponse添加表头信息
SetResponseHeaderGatewayFilterFactory 设置ServerHttpResponse的表头信息
RemoveResponseHeaderGatewayFilterFactory 从ServerHttpResponse中移除表头信息
RewriteResponseHeaderGatewayFilterFactory 重写指定ServerHttpResponse的Header的值,根据正则表达式匹配内容并进行替换
SetStatusGatewayFilterFactory 设置ServerHttpResponse的状态
PrefixPathGatewayFilterFactory 往ServerHttpRequest中添加路径前缀,保存请求URI到ServerWebExchange
RewritePathGatewayFilterFactory 按指定正则表达式替换请求URI的path,保存请求URI到ServerWebExchange
StripPrefixGatewayFilterFactory 从ServerHttpRequest去掉path的前缀信息,保存请求URI到ServerWebExchange
SetPathGatewayFilterFactory 通过设置模板重新设置path,模板的值通过HostRoutePredicate和PathRoutePredicate设置
RequestHeaderToRequestUriGatewayFilterFactory 如果ServerRequestHeader表头中存在请求URI,则将ServerWebExchange的请求URI设置为Header中的请求URI
AddRequestParameterGatewayFilterFactory 往请求URI中添加参数
HystrixGatewayFilterFactory
FallbackHeadersGatewayFilterFactory
ModifyRequestBodyGatewayFilterFactory
ModifyResponseBodyGatewayFilterFactory
PreserveHostHeaderGatewayFilterFactory 设置ServerWebExchange的属性 preserveHostHeader 为 TRUE
RedirectToGatewayFilterFactory 重定向请求到指定URI
RequestRateLimiterGatewayFilterFactory 限流处理
RetryGatewayFilterFactory
SaveSessionGatewayFilterFactory 保存Session信息
RequestSizeGatewayFilterFactory 请求大小过滤器,默认超过5000000Byte (5M) 返回错误

5. Enviroment属性优先级

bootstrap > application.yml > bootstrap.yml

6. ApplicationContext更新

参考

Hystrix之@EnableCircuitBreaker源码解读
spring-cloud-commons reference
一个可供中小团队参考的微服务架构技术栈
Spring Cloud 微服务架构学习笔记与示例
Reactive Programming 带来哪些显著的编程变化
Webflux快速入门
4_webflux服务端开发
在Sprint Boot实现Spring WebMVC与WebFlux的比较
关于java的响应式编程框架----SpringReactor
Spring boot WebFlux 简介
Springboot 2.0—WebFlux请求处理流程
第10课:WebFlux 源码剖析
详解SpringCloud-gateway动态路由两种方式,以及路由加载过程
Spring Cloud 是如何实现热更新的
深入理解SpringCloud之引导程序应用上下文
Spring Cloud Context: Application Context Services
Spring Cloud Gateway初体验
Spring Cloud Gateway 之Predict篇
spring cloud gateway之filter篇
spring cloud gateway 之限流篇
史上最简单的 SpringCloud 教程 | 终章
archaius简介
API网关spring cloud gateway和负载均衡框架ribbon实战
Spring Cloud Gateway – 熔断限流
聊聊spring cloud gateway的RetryGatewayFilter
Spring Cloud Gateway 内置的过滤器工厂
Spring Cloud Gateway 数据库存储路由信息的扩展方案

你可能感兴趣的:(Spring,Cloud)