【Ribbon】SpringCloud的Ribbon负载均衡使用

@Slf4j
@RestController
@RequestMapping(value = "/rest/content")
public class RestContentController {

    @Autowired
    private LoadBalancerClient loadbalancerClient;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/list")
    public ResultResponse list(@RequestBody CommonParam param) {
        ServiceInstance si = loadbalancerClient.choose("books-service");
        String url = String.format("http://%s:%s", si.getHost(), si.getPort());
        log.info("ribbon-url:{}", url);
        ResultResponse resultResponse = restTemplate.postForObject(url, null, ResultResponse.class);
        return resultResponse;
    }
}
# 配置被调用服务集合
books-service.ribbon.listOfServers=
  http://book-service:8086/rest/content/list,http://book-service:8087/rest/content/list

# httpClient 连接池最大总连接数
ribbon.MaxTotalConnections=200
# httpClient 每个host最大连接数
ribbon.MaxConnectionsPerHost=50