@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
文章来源地址https://www.toymoban.com/news/detail-727012.html
文章来源:https://www.toymoban.com/news/detail-727012.html
到了这里,关于【Ribbon】SpringCloud的Ribbon负载均衡使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!