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; }