Commit 4c366510 by Nepxion

增加路由策略过滤器的执行顺序配置项

parent cb4bf6b0
package com.nepxion.discovery.plugin.strategy.gateway.constant;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
public class GatewayStrategyConstant {
public static final String SPRING_APPLICATION_STRATEGY_GATEWAY_FILTER_ORDER = "spring.application.strategy.gateway.filter.order";
}
\ No newline at end of file
......@@ -13,16 +13,22 @@ import reactor.core.publisher.Mono;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.server.ServerWebExchange;
import com.nepxion.discovery.plugin.strategy.gateway.constant.GatewayStrategyConstant;
import com.nepxion.discovery.plugin.strategy.gateway.context.GatewayStrategyContext;
public class GatewayStrategyFilter implements GlobalFilter, Ordered {
private static final Logger LOG = LoggerFactory.getLogger(GatewayStrategyFilter.class);
@Autowired
private ConfigurableEnvironment environment;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
LOG.debug("Gateway strategy context is set with {}", exchange);
......@@ -34,6 +40,6 @@ public class GatewayStrategyFilter implements GlobalFilter, Ordered {
@Override
public int getOrder() {
return -400;
return environment.getProperty(GatewayStrategyConstant.SPRING_APPLICATION_STRATEGY_GATEWAY_FILTER_ORDER, Integer.class, 9999);
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ public class MyGatewayFilter implements GlobalFilter, Ordered {
@Override
public int getOrder() {
// Order必须小于-400
return -500;
// Order必须小于9999
return 9998;
}
}
\ No newline at end of file
......@@ -73,3 +73,5 @@ spring.boot.admin.client.url=http://localhost:5555
# spring.application.strategy.control.enabled=true
# 开启和关闭Ribbon默认的ZoneAvoidanceRule负载均衡策略。一旦关闭,则使用RoundRobin简单轮询负载均衡策略。缺失则默认为true
# spring.application.strategy.zone.avoidance.rule.enabled=true
# 路由策略过滤器的执行顺序(Order)。缺失则默认为9999
# spring.application.strategy.gateway.filter.order=9999
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment