<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      spring cloud gateway根據(jù)版本過(guò)濾可用實(shí)例

      根據(jù)版本過(guò)濾實(shí)例:

      import cn.hutool.core.collection.CollUtil;
      import lombok.extern.slf4j.Slf4j;
      import org.apache.commons.lang3.StringUtils;
      import org.springframework.cloud.client.ServiceInstance;
      import org.springframework.cloud.client.loadbalancer.Request;
      import org.springframework.cloud.client.loadbalancer.RequestDataContext;
      import org.springframework.cloud.loadbalancer.core.DelegatingServiceInstanceListSupplier;
      import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
      import org.springframework.http.HttpHeaders;
      import org.springframework.util.MultiValueMap;
      import reactor.core.publisher.Flux;
      
      import java.util.List;
      import java.util.stream.Collectors;
      
      @Slf4j
      public class VersionServiceInstanceListSupplier extends DelegatingServiceInstanceListSupplier {
          private static final String VERSION = "version";
      
          public VersionServiceInstanceListSupplier(ServiceInstanceListSupplier delegate) {
              super(delegate);
          }
      
      
          @Override
          public Flux<List<ServiceInstance>> get() {
              return delegate.get();
          }
      
          @Override
          public Flux<List<ServiceInstance>> get(Request request) {
              return delegate.get(request).map(instances -> filteredByVersion(instances, getVersion(request.getContext())));
          }
      
      
          private List<ServiceInstance> filteredByVersion(List<ServiceInstance> instances, String requestVersion) {
              if(StringUtils.isEmpty(requestVersion)){
                  return instances.stream()
                          .filter(instance -> StringUtils.isBlank(instance.getMetadata().get(VERSION)))
                          .collect(Collectors.toList());
              }
      
              log.info("request version is {}", requestVersion);
              List<ServiceInstance> filteredInstances = instances.stream()
                      .filter(instance -> requestVersion.equalsIgnoreCase(instance.getMetadata().get(VERSION)))
                      .collect(Collectors.toList());
      
              if (CollUtil.isEmpty(filteredInstances)) {
                  filteredInstances = instances.stream()
                          .filter(instance -> StringUtils.isBlank(instance.getMetadata().get(VERSION)))
                          .collect(Collectors.toList());
              }
              return filteredInstances;
      
          }
      
          private String getVersion(Object requestContext) {
              if (requestContext == null) {
                  return null;
              }
              String version = null;
              if (requestContext instanceof RequestDataContext) {
                  version = getVersionFromHeader((RequestDataContext) requestContext);
              }
              return version;
          }
      
          private String getVersionFromHeader(RequestDataContext context) {
              if (context.getClientRequest() != null) {
                  String version = null;
                  HttpHeaders headers = context.getClientRequest().getHeaders();
                  if (headers != null) {
                      version = headers.getFirst(VERSION);
                  }
                  if (StringUtils.isBlank(version)) {
                      MultiValueMap<String, String> cookies = context.getClientRequest().getCookies();
                      if (cookies != null) {
                          List<String> cookieVersions = cookies.get(VERSION);
                          if (CollUtil.isNotEmpty(cookieVersions)) {
                              version = cookieVersions.get(0);
                          }
                      }
                  }
                  return version;
              }
              return null;
          }
      
      }

      注冊(cè)Bean:

      import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
      import org.springframework.context.ConfigurableApplicationContext;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      
      @Configuration
      public class VersionServiceInstanceListSupplierConfiguration {
      
          @Bean
          ServiceInstanceListSupplier serviceInstanceListSupplier(ConfigurableApplicationContext context) {
              ServiceInstanceListSupplier delegate = ServiceInstanceListSupplier.builder()
                      .withDiscoveryClient()
                      .withCaching()
                      .build(context);
              return new VersionServiceInstanceListSupplier(delegate);
          }
      
      }

      啟動(dòng)類(lèi)上加:

      @LoadBalancerClients(defaultConfiguration = VersionServiceInstanceListSupplierConfiguration.class)

      以nacos注冊(cè)中心為例,網(wǎng)關(guān)加入以上代碼后,業(yè)務(wù)服務(wù)配置如下:

      spring:
        cloud:
          nacos:
            discovery:
              # 本地調(diào)試時(shí)修改以下信息
              metadata:
                ## 版本號(hào),唯一  避免與其他服務(wù)沖突
                version: V123

      請(qǐng)求接口時(shí)header帶上版本號(hào),即可路由到自己的服務(wù)

      posted @ 2024-06-21 15:15  浪天涯&*  閱讀(38)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 午夜视频免费试看| 人妻有码av中文字幕久久琪| 午夜福利看片在线观看| 亚洲午夜久久久久久噜噜噜| 国产精品久久无中文字幕 | 欧美成人片在线观看| 国产精品高清一区二区三区不卡| 久久成人伊人欧洲精品| 国产永久免费高清在线观看| 天天拍夜夜添久久精品大| 国自产拍偷拍精品啪啪一区二区| 国产福利微视频一区二区| 亚洲av无码牛牛影视在线二区 | 亚洲国产美女精品久久久| 国产精品视频亚洲二区| 亚洲中文一区二区av| 久久久天堂国产精品女人| 亚洲成人精品综合在线| 少妇爽到呻吟的视频| 国产成人综合网亚洲第一| 日本一区二区国产在线| 天堂…中文在线最新版在线 | 国产精品av中文字幕| 国产三级精品片| 制服丝袜人妻有码无码中文字幕| 日韩激情成人| 又黄又爽又色的少妇毛片| 黄色不卡视频一区二区三区| 国产色无码专区在线观看| 欧美性猛交xxxx乱大交丰满| 国产天美传媒性色av高清| 国产AV无码专区亚洲AV潘金链| 国产亚洲婷婷香蕉久久精品| 欧美人禽zozo动人物杂交| 日韩精品一区二区都可以| 国产精品人妻系列21p| av偷拍亚洲一区二区三区| 亚洲一区成人av在线| 成年男女免费视频网站| 亚洲中文字幕无码av永久| 久草国产视频|