定义
在【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