sentinel-授权规则
-
在控制台配置授权规则
-
编写请求解析类
@Component public class SentinelRequestOriginParser implements RequestOriginParser { @Override public String parseOrigin(HttpServletRequest request) { String serviceName = request.getHeader("serviceName");//接收请求头参数 if (StringUtils.isEmpty(serviceName)) return request.getRemoteAddr(); //根据ip地址处理 return serviceName; } }
在微服务中服务和服务直接的调用可以使用feign的请求拦截器:
@Bean public RequestInterceptor requestInterceptor(){ return template -> template.header("serviceName","pc"); }