Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
VangelisHaha opened this issue Jan 31, 2020 · 4 comments
Closed

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

VangelisHaha opened this issue Jan 31, 2020 · 4 comments

Comments

@VangelisHaha
Copy link

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

  • gateway
  • eureka
  • apollo
  • service-a_1.0,service-a_1.1(显示名)
  • auth

问题:
在集成测试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
Copy link
Author

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

@HaojunRen
Copy link
Member

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

@VangelisHaha
Copy link
Author

感谢回答,此问题已经排查发现问题所在,我正在将网关端全链路路由策略的灰度发布规则放入Apollo中,发现Apollo只支持维护 properties 即为 key->value 类似

我在其他issue中找到您说可以使用 key -xml 方式放入配置中心即可,但是我查阅源码实在不知道key 该怎么定义,它是否是strategy=xml配置/json配置 ?

@HaojunRen
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants