springcloud全局过滤_Spring Cloud Gateway全局过滤器GlobalFilter初探

本文介绍了Spring Cloud Gateway的全局过滤器GlobalFilter,包括其接口定义、内置实现类及其实例化配置。GlobalFilter作用于所有路由,其内置实现类如AdaptCachedBodyGlobalFilter、ForwardRoutingFilter等具有不同优先级。默认实例化8个实现类,某些如LoadBalancerClientFilter需特定条件。更多过滤器的作用将在后续文章中探讨。
摘要由CSDN通过智能技术生成

定义

在【spring cloud gateway】的官方文档中,全局过滤器GlobalFilter接口是这样定义的:

The GlobalFilter interface has the same signature as GatewayFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones).

GlobalFilter 和 GatewayFilter 的 #filter(ServerWebExchange, GatewayFilterChain) 方法签名一致;

GlobalFilter会作用于所有的路由上;

在未来的里程碑版本中可能作一些调整;

org.springframework.cloud.gateway.filter.GlobalFilter,接口源代码:

public interface GlobalFilter {

/**

* Process the Web request and (optionally) delegate to the next

* {@code WebFilter} through the given {@link GatewayFilterChain}.

* @param exchange the current server exchange

* @param chain provides a way to delegate to the next filter

* @return {@code Mono} to indicate when request processing is complete

*/

Mono filter(ServerWebExchange exchange, GatewayFilterChain chain);

}

GlobalFilter实现类

关于GlobalFilter接口内置的实现类主要有11个,均位于 org.springframework.cloud.gateway.filter 包中,如下:

IDEA查看类图快捷键

Ctrl + Alt + Shift + U:查看GlobalFilter类图;

Ctrl + T:查看GlobalFilter接口的所有实现类;

各个实现类的顺序如下( 数值越小,优先级越高,括号中为源码中的值 ):

AdaptCachedBodyGlobalFilter :-2147482648 ( Ordered.HIGHEST_PRECEDENCE + 1000 )

ForwardPathFilter:0

ForwardRoutingFilter:2147483647 ( Ordered.LOWEST_PRECEDENCE )

GatewayMetricsFilter:0

LoadBalancerClientFilter:10100

NettyRoutingFilter:2147483647 ( Ordered.LOWEST_PRECEDENCE )

NettyWriteResponseFilter:-1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值