springbootconfigfeignstarter

spring cloud zuul扩展灰度权限等

2017-07-16  本文已影响827人  jey恒

灰度方案

目前现状分析

灰度方式

[
    {
        "toServerId": "localhost:8585", 
        "userList": null, 
        "app": "tsms", 
        "serverIdList": [
            "localhost:8080", 
            "localhost:8585"
        ], 
        "graying": true
    }
]

灰度结合发布的流程

实现

tsms:
  ribbon:
    listOfServers: localhost:8080, localhost:8585

tsms:
  ribbon:
   NFLoadBalancerRuleClassName: com.xxx.xxx.gateway.ribbon.GrayLoadBalancerRule

GrayLoadBalancerRule 我们自定义的ribbon复杂均衡

@Override
  public Server choose(Object key) {
    RequestContext requestContext = RequestContext.getCurrentContext();

   权限控制filter解码后 得到用户id
    String userId = (String) requestContext.get(Constants.ACCESS_USER_ID);

    DynamicServerListLoadBalancer loadBalancer = (DynamicServerListLoadBalancer) getLoadBalancer();

    if (loadBalancer == null) {
      log.warn("no load balancer");
      return null;
    }

    List<Server> serverList = loadBalancer.getReachableServers();

    String client = loadBalancer.getClientConfig().getClientName();

    GrayHolderInfo grayHolderInfo = grayService.grayByUserId(client, serverList, userId);

    if (grayHolderInfo.getGrayServer().isPresent()) {

      return grayHolderInfo.getGrayServer().get();
    }
    轮询
    return roundRuleChoose(client, loadBalancer, grayHolderInfo);
  }

需要做的

上一篇 下一篇

猜你喜欢

热点阅读