1.Ribbon组件
RestTemplate配置时添加@LoadBalanced,可以实现调用接口的轮询。
代码片段
@PostMapping("/ribbonTst01")
public String ribbonTst() throws Exception
{
return restTemplate.getForObject("http://ruoyi-system/ribbon/ribbonTst",String.class);
}
链接中的ruoyi-system为服务名,ribbon通过拦截器拦截,LoadBalancerInterceptor.intercept()将服务名换成存储在nacos服务中ip地址
image.png
调用结果如下
image.png
注意:此处调用为服务之间调用,没有通过网关调用












网友评论