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

DiscoveryClientDecorator只有在版本偏好和版本故障转移打开后才有效么? #179

Open
HelloLong opened this issue Jan 11, 2022 · 1 comment

Comments

@HelloLong
Copy link

HelloLong commented Jan 11, 2022

DefaultDiscoveryEnabledAdapter.java

 if (StringUtils.isEmpty(versions)) {
           // 版本偏好,即非蓝绿灰度发布场景下,路由到老的稳定版本的实例
           if (versionPreferEnabled) {
               return strategyVersionFilter.apply(server);
           } else {
               return true;
           }
       } else {
           // 版本故障转移,即无法找到相应版本的服务实例,路由到老的稳定版本的实例
           if (versionFailoverEnabled) {
               List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);

               boolean matched = false;
               for (ServiceInstance instance : instances) {
                   if (strategyVersionFilter.applyVersion(instance)) {
                       matched = true;

                       break;
                   }
               }

               if (!matched) {
                   return strategyVersionFilter.apply(server);
               }
           }
       }

当 spring.application.strategy.version.prefer.enabled 和 spring.application.strategy.version.failover.enabled 未开启时,无法走到
DiscoveryClientDecorator.getInstances 所以也无法走到 VersionFilterDiscoveryListener。

@HaojunRen
Copy link
Member

HaojunRen commented Feb 15, 2022

不好意思,迟至今日回复。DiscoveryClientDecorator中版本偏好和版本故障转移,它只是获取实例列表的一种策略手段

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