网关_zuul_灰度发布
作者:互联网
yml:
配置灰度规则,这里使用eureka元数据,做处理,需要网关转发的服务,配置元数据信息,这里使用version代表不同版本
--- spring: profiles: 8081 eureka: instance: metadata-map: version: v1 server: port: 8081 --- spring: profiles: 8082 eureka: instance: metadata-map: version: v2 server: port: 8082
java:
假如通过用户id,判断不同用户进入不同的服务
@Override public Object run() throws ZuulException { RequestContext currentContext = RequestContext.getCurrentContext(); HttpServletRequest request = currentContext.getRequest(); String userid=request.getHeader("userid"); if("1".equals(userid)){ RibbonFilterContextHolder.getCurrentContext().add("version","v2"); }else{ RibbonFilterContextHolder.getCurrentContext().add("version","v1"); } return null; }
标签:网关,zuul,RequestContext,userid,eureka,getCurrentContext,version,灰度 来源: https://www.cnblogs.com/fch2w/p/15367755.html