Nepxion / Discovery

☀️ Nepxion Discovery is a solution for Spring Cloud with blue green, gray, route, limitation, circuit breaker, degrade, isolation, tracing, dye, failover, active 蓝绿灰度发布、路由、限流、熔断、降级、隔离、追踪、流量染色、故障转移、多活
http://www.nepxion.com
Apache License 2.0
5.63k stars 1.43k forks source link

ServerWebExchange对象在线程切换时丢失 #92

Closed VangelisHaha closed 4 years ago

VangelisHaha commented 4 years ago

环境:SpringCloud :Finchley
Discovery:4.13.5 版本匹配 pom依赖检查无错误 启动项目

问题: 在集成测试sevice-a 时使用Header 参数 指定了 n-d-version: {"service-a":"1.1"} 对应eurekametadata也指定了对应version 和group 实际结果版本指定规则未生效

于是乎一路Debug

@Override
    public String getHeader(String name) {
       // 检查到此处发现从线程中获取ServerWebExchange 为null,排查无果
        ServerWebExchange exchange = getExchange();
        if (exchange == null) {
            LOG.warn("The ServerWebExchange object is lost for thread switched, or it is got before context filter probably");

            return null;
        }
        return exchange.getRequest().getHeaders().getFirst(name);
    }

如上所示,导致Header 中n-d-version 参数获取不到,作者大大这是为啥呀

VangelisHaha commented 4 years ago

我正在做的事情是使用传递Header从而版本匹配的灰度路由策略

HaojunRen commented 4 years ago

因为你可能用了Hystrix线程池隔离模式,请参考DiscoveryGuide的README

VangelisHaha commented 4 years ago

感谢回答,此问题已经排查发现问题所在,我正在将网关端全链路路由策略的灰度发布规则放入Apollo中,发现Apollo只支持维护 properties 即为 key->value 类似
我在其他issue中找到您说可以使用 key -xml 方式放入配置中心即可,但是我查阅源码实在不知道key 该怎么定义,它是否是strategy=xml配置/json配置 ?

HaojunRen commented 4 years ago

是的。请在Discovery首页找一下,有Apollo如何配置的截图和说明文字