SpringCloudGateway中的过滤器是否有推荐的订购范围?

ssm49v7z  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(215)

我想知道spring cloud gateway中是否有网关过滤器(全局或非全局)的建议订单范围,因为网关链中存在订单小于1且大于9999的spring gateway过滤器。见:

{OrderedGatewayFilter@20770} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter@5eb974}, order = -2147483648]"
{OrderedGatewayFilter@20771} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@ae5eeee}, order = -2147482648]"
{OrderedGatewayFilter@20772} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@492c1b1b}, order = -1]"
{OrderedGatewayFilter@20774} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@3927de0e}, order = 0]"
{OrderedGatewayFilter@20775} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.GatewayMetricsFilter@36dab184}, order = 0]"

// my custom filters should be here

{OrderedGatewayFilter@20791} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@72f112d1}, order = 10000]"
{OrderedGatewayFilter@20792} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.config.GatewayNoLoadBalancerClientAutoConfiguration$NoLoadBalancerClientFilter@71b9b035}, order = 10150]"
{OrderedGatewayFilter@20793} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@4c475547}, order = 2147483646]"
{OrderedGatewayFilter@20794} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@189f5ed8}, order = 2147483647]"
{OrderedGatewayFilter@20795} "[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@10faebc9}, order = 2147483647]"

我的自定义全局筛选器实现有序接口:

@Component
public class GlobalFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ... }

    @Override
    public int getOrder() {
        return 2; // here
    }
}

我的网关过滤器是orderedgatewayfilter:

@Component
public class CustomFilter implements GatewayFilterFactory<CustomFilter.Config> {

    @Override
    public GatewayFilter apply(Config config) {
        return new OrderedGatewayFilter((exchange, chain) -> {
           ...
        }, 3); // here
    }

   ...
}

我的过滤器应该在1..9999范围内吗?或者在这些SpringCloudGateway过滤器之前或之后放置我的自定义过滤器没有问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题