软件定制开发供应商微服务之负载均衡组件Ribbon

一:软件定制开发供应商负载均衡的二种实现

1.1)软件定制开发供应商服务端的负载均衡(Nginx)

①:软件定制开发供应商我们用户服务发送请求软件定制开发供应商首先打到上,然后Ng软件定制开发供应商根据负载均衡算法进行软件定制开发供应商选择一个服务调 用,而我们的Ng软件定制开发供应商部署在服务器上的,所以Ng软件定制开发供应商又称为服务端的负载均衡(软件定制开发供应商具体调用哪个服务, 由Ng所了算)

1.2)软件定制开发供应商客户端负载均衡(

spring cloud ribbon是 基于NetFilix ribbon 软件定制开发供应商实现的一套客户端的负载 均衡工具,Ribbon软件定制开发供应商客户端组件提供一系列软件定制开发供应商的完善的配置,如超时,重试 等。

通过Load Balancer(LB)获取到服务提供的所有机器实例,Ribbon 会自动基于某种规则(轮询,随机)去调用这些服务。Ribbon也可以实 现 我们自己的。

 1.3)自定义的负载均衡算法(随机)

可以通过DiscoveryClient组件来去我们的Nacos服务端 拉取给名称的微服务列表。我们可以通过这个特性来改写我们的RestTemplate 组件.

①:经过阅读源码RestTemplate组件得知,不管是post,get请求最终是会调 用我们的doExecute()方法,所以我们写一个MyRestTemplate类继承 RestTemplate,从写doExucute()方法。

  1. @Slf4j
  2. public class MyRestTemplate extends RestTemplate {
  3. private DiscoveryClient discoveryClient;
  4. public MyRestTemplate (DiscoveryClient discoveryClient) {
  5. this.discoveryClient = discoveryClient;
  6. }
  7. protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullab
  8. le RequestCallback requestCallback,
  9. @Nullable ResponseExtractor<T> responseExtractor) throws RestClientExce
  10. ption {
  11. Assert.notNull(url, "URI is required");
  12. Assert.notNull(method, "HttpMethod is required");
  13. ClientHttpResponse response = null;
  14. try {
  15. //判断url的拦截路径,然后去redis(作为注册中心)获取地址随机选取一个
  16. log.info("请求的url路径为:{}",url);
  17. url = replaceUrl(url);
  18. log.info("替换后的路径:{}",url);
  19. ClientHttpRequest request = createRequest(url, method);
  20. if (requestCallback != null) {
  21. requestCallback.doWithRequest(request);
  22. }
  23. response = request.execute();
  24. handleResponse(url, method, response);
  25. return (responseExtractor != null ? responseExtractor.extractData(respo
  26. nse) : null);
  27. }
  28. catch (IOException ex) {
  29. String resource = url.toString();
  30. String query = url.getRawQuery();
  31. resource = (query != null ? resource.substring(0,
  32. resource.indexOf('?')) : resource);
  33. throw new ResourceAccessException("I/O error on " + method.name() +
  34. " request for \"" + resource + "\": " + ex.getMessage(), ex);
  35. } finally {
  36. if (response != null) {
  37. response.close();
  38. }
  39. }
  40. }
  41. /**
  42. * 把服务实例名称替换为ip:端口
  43. * @param url
  44. * @return
  45. */
  46. private URI replaceUrl(URI url){
  47. //解析我们的微服务的名称
  48. String sourceUrl = url.toString();
  49. String [] httpUrl = sourceUrl.split("//");
  50. int index = httpUrl[1].replaceFirst("/","@").indexOf("@");
  51. String serviceName = httpUrl[1].substring(0,index);
  52. //通过微服务的名称去nacos服务端获取 对应的实例列表
  53. List<ServiceInstance> serviceInstanceList = discoveryClient.getInstance
  54. s(serviceName);
  55. if(serviceInstanceList.isEmpty()) {
  56. throw new RuntimeException("没有可用的微服务实例列表:"+serviceName);
  57. }
  58. //采取随机的获取一个
  59. Random random = new Random();
  60. Integer randomIndex = random.nextInt(serviceInstanceList.size());
  61. log.info("随机下标:{}",randomIndex);
  62. String serviceIp = serviceInstanceList.get(randomIndex).getUri().toStri
  63. ng();
  64. log.info("随机选举的服务IP:{}",serviceIp);
  65. String targetSource = httpUrl[1].replace(serviceName,serviceIp);
  66. try {
  67. return new URI(targetSource);
  68. } catch (URISyntaxException e) {
  69. e.printStackTrace();
  70. }
  71. return url;
  72. }
  73. }

1.4)通过Ribbon组件来实习负载均衡(默认的负载均衡算法是 轮询)

①:创建整合Ribbon的工程:

服务消费者(order) 服务提供者(product)****服务提供者不需 要Ribbon的依赖

第一步:加入依赖(加入nocas-client和ribbon的依赖)

  1. <!‐‐加入nocas‐client‐‐>
  2. <dependency>
  3. <groupId>com.alibaba.cloud</groupId>
  4. <artifactId>spring‐cloud‐alibaba‐nacos‐discovery</artifactId>
  5. </dependency>
  6. <!‐‐加入ribbon‐‐>
  7. <dependency>
  8. <groupId>org.springframework.cloud</groupId>
  9. <artifactId>spring‐cloud‐starter‐netflix‐ribbon</artifactId>
  10. </dependency>

第二步:写注解: 在RestTemplate上加入@LoadBalanced注解

  1. @Configuration
  2. public class WebConfig {
  3. @LoadBalanced
  4. @Bean
  5. public RestTemplate restTemplate( ) {
  6. return new RestTemplate();
  7. }
  8. }

第三步:写配置文件(这里是写Nacos 的配置文件,暂时没有配置Ribbon的配置)

  1. spring:
  2. cloud:
  3. nacos:
  4. discovery:
  5. server‐addr: localhost:8848
  6. application:
  7. name: order‐center

启动技巧: 我们启动服务提供者的技巧(并行启动)

1)我们的product的端口是8081,我们用 8081启动一个服务后,然后修改端口为8082,然后修改下图,那么就可以同一 个工程启动二个实例

1.5)Ribbon的内置的负载均衡算法

 

 ①:RandomRule(随机选择一个Server)

②:RetryRule 对选定的负载均衡策略(轮询)基础上重试机制,在一个配置时间段内当选择Server不成功, 则一直尝试使用subRule的方式选择一个可用的server.

③:RoundRobinRule 轮询选择, 轮询index,选择index对应位置的Server ④:AvailabilityFilteringRule 过滤掉一直连接失败的被标记为circuit tripped的后端Server,并过滤掉那些高并发的后端 Server或者使用一个AvailabilityPredicate来包含过滤server的逻辑,其实就就是检查 status里记录的各个Server的运行状态

⑤:BestAvailableRule 选择一个最小的并发请求的Server,逐个考察Server,如果Server被tripped了,则跳过。

⑥:WeightedResponseTimeRule 根据响应时间加权,响应时间越长,权重越小,被选中的可能性越低;

⑦:ZoneAvoidanceRule(默认是这个) 复合判断Server所在Zone的性能和Server的可用性选择Server,在没有Zone的情况下类是 轮询。

1.6)Ribbon的细粒度自定义配置

场景:我订单中心需要采用随机算法调用 库存中心 而采用轮询算法调用其他中心微服务。 基于java代码细粒度配置

**注意点**

我们针对调用具体微服务的具体配置类 ProductCenterRibbonConfig,OtherCenterRibbonConfig不能被放在我们主启动类所 在包以及子包下,不然就起不到细粒度配置

  1. @Configuration
  2. @RibbonClients(value = {
  3. @RibbonClient(name = "product‐center",configuration = ProductCenterRibbonConfig.class),
  4. @RibbonClient(name = "pay‐center",configuration =
  5. PayCenterRibbonConfig.class)
  6. })
  7. public class CustomRibbonConfig {
  8. }
  9. @Configuration
  10. public class ProductCenterRibbonConfig {
  11. @Bean
  12. public IRule randomRule() {
  13. return new RandomRule();
  14. }
  15. }
  16. @Configuration
  17. public class PayCenterRibbonConfig {
  18. public IRule roundRobinRule() {
  19. return new RoundRobinRule();
  20. }
  21. }

基于yml配置:(我们可以在order-center的yml中进行配置) 配置格式的语法如下

serviceName:

        ribbon:

                NFLoadBalancerRuleClassName: 负载均衡的对应class的全类名

配置案例: 我们的order-center调用我们的product-center

  1. #自定义Ribbon的细粒度配置
  2. product‐center:
  3. ribbon:
  4. NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
  5. pay‐center:
  6. ribbon:
  7. NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RoundRobinRule

1.7)解决Ribbon 第一次调用耗时高的配置

开启饥饿加载

  1. ribbon:
  2. eager‐load:
  3. enabled: true
  4. clients: product‐center #可以指定多个微服务用逗号分隔

常用参数讲解:

每一台服务器重试的次数,不包含首次调用的那一次
ribbon.MaxAutoRetries=1

# 重试的服务器的个数,不包含首次调用的那一台实例
ribbon.MaxAutoRetriesNextServer=2

# 是否对所有的操作进行重试(True 的话 会对post put操作进行重试,存在服务幂等问
题)
ribbon.OkToRetryOnAllOperations=true

 # 建立连接超时
 ribbon.ConnectTimeout=3000

 # 读取数据超时
 ribbon.ReadTimeout=3000

 举列子: 上面会进行几次重试
 MaxAutoRetries
 +
 MaxAutoRetriesNextServer
 +
 (MaxAutoRetries *MaxAutoRetriesNextServer)

 Ribbon详细配置:

1.8)Ribbon 自定义负载均衡策略

我们发现,nacos server上的页面发现 注册的微服务有一个权重的概 念。 取值为0-1之间

 权重选择的概念: 假设我们一个微服务部署了三台服务器A,B,C 其中A,B,C三台服务的性能不一,A的性能最牛逼,B次之,C最差. 那么我们设置权重比例 为5 : 3:2 那就说明 10次请求到A上理论是5次,B 服务上理论是3次,B服务理论是2次.

①:但是Ribbon 所提供的负载均衡算法中没有基于权重的负载均衡算 法。我们自己实现一个.

  1. @Slf4j
  2. public class TulingWeightedRule extends AbstractLoadBalancerRule {
  3. @Autowired
  4. private NacosDiscoveryProperties discoveryProperties;
  5. @Override
  6. public void initWithNiwsConfig(IClientConfig clientConfig) {
  7. //读取配置文件并且初始化,ribbon内部的 几乎用不上
  8. }
  9. @Override
  10. public Server choose(Object key) {
  11. try {
  12. log.info("key:{}",key);
  13. BaseLoadBalancer baseLoadBalancer = (BaseLoadBalancer) this.getLoadBala
  14. ncer();
  15. log.info("baseLoadBalancer‐‐‐>:{}",baseLoadBalancer);
  16. //获取微服务的名称
  17. String serviceName = baseLoadBalancer.getName();
  18. //获取Nocas服务发现的相关组件API
  19. NamingService namingService =
  20. discoveryProperties.namingServiceInstance();
  21. //获取 一个基于nacos client 实现权重的负载均衡算法
  22. Instance instance =
  23. namingService.selectOneHealthyInstance(serviceName);
  24. //返回一个server
  25. return new NacosServer(instance);
  26. } catch (NacosException e) {
  27. log.error("自定义负载均衡算法错误");
  28. }
  29. return null;
  30. }
  31. }

进阶版本1:我们发现Nacos领域模型中有一个集群的概念 同集群优先权重负载均衡算法

业务场景:现在我们有二个微服务order-center, product-center二个微服 务。我们在南京机房部署一套order-center,product-center。为了容灾处 理,我们在北京同样部署一套order-center,product-center

 

  1. @Slf4j
  2. public class TheSameClusterPriorityRule extends AbstractLoadBalancerRule
  3. {
  4. @Autowired
  5. private NacosDiscoveryProperties discoveryProperties;
  6. @Override
  7. public void initWithNiwsConfig(IClientConfig clientConfig) {
  8. }
  9. @Override
  10. public Server choose(Object key) {
  11. try {
  12. //第一步:获取当前服务所在的集群
  13. String currentClusterName = discoveryProperties.getClusterName();
  14. //第二步:获取一个负载均衡对象
  15. BaseLoadBalancer baseLoadBalancer = (BaseLoadBalancer)
  16. getLoadBalancer();
  17. //第三步:获取当前调用的微服务的名称
  18. String invokedSerivceName = baseLoadBalancer.getName();
  19. //第四步:获取nacos clinet的服务注册发现组件的api
  20. NamingService namingService =
  21. discoveryProperties.namingServiceInstance();
  22. //第五步:获取所有的服务实例
  23. List<Instance> allInstance = namingService.getAllInstances(invokedSeriv
  24. ceName);
  25. List<Instance> theSameClusterNameInstList = new ArrayList<>();
  26. //第六步:过滤筛选同集群下的所有实例
  27. for(Instance instance : allInstance) {
  28. if(StringUtils.endsWithIgnoreCase(instance.getClusterName(),currentClus
  29. terName)) {
  30. theSameClusterNameInstList.add(instance);
  31. }
  32. }
  33. Instance toBeChooseInstance ;
  34. //第七步:选择合适的一个实例调用
  35. if(theSameClusterNameInstList.isEmpty()) {
  36. toBeChooseInstance = TulingWeightedBalancer.chooseInstanceByRandomWeigh
  37. t(allInstance);
  38. log.info("发生跨集群调用‐‐‐>当前微服务所在集群:{},被调用微服务所在集群:{},Ho
  39. st:{},Port:{}",
  40. currentClusterName,toBeChooseInstance.getClusterName(),toBeChooseInstan
  41. ce.getIp(),toBeChooseInstance.getPort());
  42. }else {
  43. toBeChooseInstance = TulingWeightedBalancer.chooseInstanceByRandomWeigh
  44. t(theSameClusterNameInstList);
  45. log.info("同集群调用‐‐‐>当前微服务所在集群:{},被调用微服务所在集群:{},Host:
  46. {},Port:{}",
  47. currentClusterName,toBeChooseInstance.getClusterName(),toBeChooseInstan
  48. ce.getIp(),toBeChooseInstance.getPort());
  49. }
  50. return new NacosServer(toBeChooseInstance);
  51. } catch (NacosException e) {
  52. log.error("同集群优先权重负载均衡算法选择异常:{}",e);
  53. }
  54. return null;
  55. }
  56. }
  57. /**
  58. * 根据权重选择随机选择一个
  59. * Created by smlz on 2019/11/21.
  60. */
  61. public class TulingWeightedBalancer extends Balancer {
  62. public static Instance chooseInstanceByRandomWeight(List<Instance> host
  63. s) {
  64. return getHostByRandomWeight(hosts);
  65. }
  66. }

 配置文件

  1. spring
  2. cloud:
  3. nacos:
  4. discovery:
  5. server-addr: localhost:8848
  6. #配置集群名称
  7. cluster-name: NJ-CLUSTER
  8. #namespace: bc7613d2-2e22-4292-a748-48b78170f14c #指定namespace的id
  9. application:
  10. name: order-center

进阶版本2: 根据进阶版本1,我们现在需要解决生产环境金丝雀发布问题 比如 order-center 存在二个版本 V1(老版本) V2(新版 本),product-center也存在二个版本V1(老版本) V2新版本 现在需要 做到的是

order-center(V1)---->product-center(v1),

order-center(V2)--- ->product-center(v2)。

记住v2版本是小面积部署的,用来测试用 户对新版本功能的。若用户完全接受了v2。我们就可以把V1版本卸载 完全部署V2版本。

 代码实现思路:通过我们实例的元数据控制

  1. /**
  2. * 同一个集群,同已版本号 优先调用策略
  3. * Created by smlz on 2019/11/21.
  4. */
  5. @Slf4j
  6. public class TheSameClusterPriorityWithVersionRule extends AbstractLoadBa
  7. lancerRule {
  8. @Autowired
  9. private NacosDiscoveryProperties discoveryProperties;
  10. @Override
  11. public void initWithNiwsConfig(IClientConfig clientConfig) {
  12. }
  13. @Override
  14. public Server choose(Object key) {
  15. try {
  16. String currentClusterName = discoveryProperties.getClusterName();
  17. List<Instance> theSameClusterNameAndTheSameVersionInstList = getTheSame
  18. ClusterAndTheSameVersionInstances(discoveryProperties);
  19. //声明被调用的实例
  20. Instance toBeChooseInstance;
  21. //判断同集群同版本号的微服务实例是否为空
  22. if(theSameClusterNameAndTheSameVersionInstList.isEmpty()) {
  23. //跨集群调用相同的版本
  24. toBeChooseInstance = crossClusterAndTheSameVersionInovke(discoveryPrope
  25. rties);
  26. }else {
  27. toBeChooseInstance = TulingWeightedBalancer.chooseInstanceByRandomWeigh
  28. t(theSameClusterNameAndTheSameVersionInstList);
  29. log.info("同集群同版本调用‐‐‐>当前微服务所在集群:{},被调用微服务所在集群:{},
  30. 当前微服务的版本:{},被调用微服务版本:{},Host:{},Port:{}",
  31. currentClusterName,toBeChooseInstance.getClusterName(),discoveryPropert
  32. ies.getMetadata().get("current‐version"),
  33. toBeChooseInstance.getMetadata().get("current‐version"),toBeChooseInsta
  34. nce.getIp(),toBeChooseInstance.getPort());
  35. }
  36. return new NacosServer(toBeChooseInstance);
  37. } catch (NacosException e) {
  38. log.error("同集群优先权重负载均衡算法选择异常:{}",e);
  39. return null;
  40. }
  41. }
  42. /**
  43. * 方法实现说明:获取相同集群下,相同版本的 所有实例
  44. * @author:smlz
  45. * @param discoveryProperties nacos的配置
  46. * @return: List<Instance>
  47. * @exception: NacosException
  48. * @date:2019/11/21 16:41
  49. */
  50. private List<Instance> getTheSameClusterAndTheSameVersionInstances(Naco
  51. sDiscoveryProperties discoveryProperties) throws NacosException {
  52. //当前的集群的名称
  53. String currentClusterName = discoveryProperties.getClusterName();
  54. String currentVersion = discoveryProperties.getMetadata().get("current‐
  55. version");
  56. //获取所有实例的信息(包括不同集群的)
  57. List<Instance> allInstance = getAllInstances(discoveryProperties);
  58. List<Instance> theSameClusterNameAndTheSameVersionInstList = new ArrayL
  59. ist<>();
  60. //过滤相同集群的
  61. for(Instance instance : allInstance) {
  62. if(StringUtils.endsWithIgnoreCase(instance.getClusterName(),currentClus
  63. terName)&&
  64. StringUtils.endsWithIgnoreCase(instance.getMetadata().get("current‐vers
  65. ion"),currentVersion)) {
  66. theSameClusterNameAndTheSameVersionInstList.add(instance);
  67. }
  68. }
  69. return theSameClusterNameAndTheSameVersionInstList;
  70. }
  71. /**
  72. * 方法实现说明:获取被调用服务的所有实例
  73. * @author:smlz
  74. * @param discoveryProperties nacos的配置
  75. * @return: List<Instance>
  76. * @exception: NacosException
  77. * @date:2019/11/21 16:42
  78. */
  79. private List<Instance> getAllInstances(NacosDiscoveryProperties discove
  80. ryProperties) throws NacosException {
  81. //第1步:获取一个负载均衡对象
  82. BaseLoadBalancer baseLoadBalancer = (BaseLoadBalancer)
  83. getLoadBalancer();
  84. //第2步:获取当前调用的微服务的名称
  85. String invokedSerivceName = baseLoadBalancer.getName();
  86. //第3步:获取nacos clinet的服务注册发现组件的api
  87. NamingService namingService =
  88. discoveryProperties.namingServiceInstance();
  89. //第4步:获取所有的服务实例
  90. List<Instance> allInstance = namingService.getAllInstances(invokedSeriv
  91. ceName);
  92. return allInstance;
  93. }
  94. /**
  95. * 方法实现说明:跨集群环境下 相同版本的
  96. * @author:smlz
  97. * @param discoveryProperties
  98. * @return: List<Instance>
  99. * @exception: NacosException
  100. * @date:2019/11/21 17:11
  101. */
  102. private List<Instance> getCrossClusterAndTheSameVersionInstList(NacosDi
  103. scoveryProperties discoveryProperties) throws NacosException {
  104. //版本号
  105. String currentVersion = discoveryProperties.getMetadata().get("current‐
  106. version");
  107. //被调用的所有实例
  108. List<Instance> allInstance = getAllInstances(discoveryProperties);
  109. List<Instance> crossClusterAndTheSameVersionInstList = new ArrayList<>
  110. ();
  111. //过滤相同版本
  112. for(Instance instance : allInstance) {
  113. if(StringUtils.endsWithIgnoreCase(instance.getMetadata().get("current‐v
  114. ersion"),currentVersion)) {
  115. crossClusterAndTheSameVersionInstList.add(instance);
  116. }
  117. }
  118. return crossClusterAndTheSameVersionInstList;
  119. }
  120. private Instance crossClusterAndTheSameVersionInovke(NacosDiscoveryProp
  121. erties discoveryProperties) throws NacosException {
  122. //获取所有集群下相同版本的实例信息
  123. List<Instance> crossClusterAndTheSameVersionInstList = getCrossClusterA
  124. ndTheSameVersionInstList(discoveryProperties);
  125. //当前微服务的版本号
  126. String currentVersion = discoveryProperties.getMetadata().get("current‐
  127. version");
  128. //当前微服务的集群名称
  129. String currentClusterName = discoveryProperties.getClusterName();
  130. //声明被调用的实例
  131. Instance toBeChooseInstance = null ;
  132. //没有对应相同版本的实例
  133. if(crossClusterAndTheSameVersionInstList.isEmpty()) {
  134. log.info("跨集群调用找不到对应合适的版本当前版本为:currentVersion:{}",curr
  135. entVersion);
  136. throw new RuntimeException("找不到相同版本的微服务实例");
  137. }else {
  138. toBeChooseInstance = TulingWeightedBalancer.chooseInstanceByRandomWeigh
  139. t(crossClusterAndTheSameVersionInstList);
  140. log.info("跨集群同版本调用‐‐‐>当前微服务所在集群:{},被调用微服务所在集群:
  141. {},当前微服务的版本:{},被调用微服务版本:{},Host:{},Port:{}",
  142. currentClusterName,toBeChooseInstance.getClusterName(),discoveryPropert
  143. ies.getMetadata().get("current‐version"),
  144. toBeChooseInstance.getMetadata().get("current‐version"),toBeChooseInsta
  145. nce.getIp(),toBeChooseInstance.getPort());
  146. }
  147. return toBeChooseInstance;
  148. }
  149. }

配置文件说明

order-center的yml的配置

  1. spring:
  2. cloud:
  3. nacos:
  4. discovery:
  5. server-addr: localhost:8848
  6. #所在集群
  7. cluster-name: NJ-CLUSTER
  8. metadata:
  9. #版本号
  10. current-version: V1
  11. #namespace: bc7613d2-2e22-4292-a748-48b78170f14c #指定namespace的id
  12. application:
  13. name: order-center

product-center的yml配置说明:

NJ-CLUSTER下的V1版本 

  1. spring:
  2. application:
  3. name: product‐center
  4. cloud:
  5. nacos:
  6. discovery:
  7. server‐addr: localhost:8848
  8. cluster‐name: NJ‐CLUSTER
  9. metadata:
  10. current‐version: V1
  11. #namespace: 20989a73‐cdb3‐41b8‐85c0‐e9a3530e28a6
  12. server:
  13. port: 8084

NJ-CLUSTER下的V2版本

  1. spring:
  2. application:
  3. name: product‐center
  4. cloud:
  5. nacos:
  6. discovery:
  7. server‐addr: localhost:8848
  8. cluster‐name: NJ‐CLUSTER
  9. metadata:
  10. current‐version: V2
  11. #namespace: 20989a73‐cdb3‐41b8‐85c0‐e9a3530e28a6
  12. server:
  13. port: 8083

BJ-CLUSTER下的V1版本

  1. spring:
  2. application:
  3. name: product‐center
  4. cloud:
  5. nacos:
  6. discovery:
  7. server‐addr: localhost:8848
  8. cluster‐name: BJ‐CLUSTER
  9. metadata:
  10. current‐version: V1
  11. #namespace: 20989a73‐cdb3‐41b8‐85c0‐e9a3530e28a6
  12. server:
  13. port: 8082

 BJ-CLUSTER下的V2版本

  1. spring:
  2. application:
  3. name: product‐center
  4. cloud:
  5. nacos:
  6. discovery:
  7. server‐addr: localhost:8848
  8. cluster‐name: BJ‐CLUSTER
  9. metadata:
  10. current‐version: V2
  11. #namespace: 20989a73‐cdb3‐41b8‐85c0‐e9a3530e28a6
  12. server:
  13. port: 8081

测试说明: 从我们的order-center调用product-center的时候 优先会调用同集群同版本 的 2022-2-09 22:42:42.317 INFO 45980 --- [nio-8080-exec-3] .m.TheSameClusterPriorityWithVersionRule : 同集群同版本调用--->当前微服务所在 集群:NJ-CLUSTER,被调用微服务所在集群:NJ-CLUSTER,当前微服务的版本:V1,被调用微 服务版本:V1,Host:192.168.0.120,Port:8081

若我们把同集群的 同版本的product-center下线,那们就会发生跨集群调用相同的版本:

 

2022-2-09 22:44:48.723 INFO 45980 --- [nio-8080-exec-6] .m.TheSameClusterPriorityWithVersionRule : 跨集群同版本调用--->当前微服务所在 集群:NJ-CLUSTER,被调用微服务所在集群:BJ-CLUSTER,当前微服务的版本:V1,被调用微 服务版本:V1,Host:192.168.0.120,Port:8083 

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发