当前位置:网站首页>Ribbon service call
Ribbon service call
2022-04-23 22:10:00 【Leon_ Jinhai_ Sun】
# 1. Introducing dependencies into a project
- explain :
1. If you are using eureka client and consul client, There is no need to introduce dependencies , Because in eureka,consul Integrated by default in ribbon Components
2. If used client There is no ribbon Dependencies need to explicitly introduce the following dependencies
<!-- introduce ribbon rely on -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
# 2. see consul client Depending on ribbon
# 3. Use restTemplate + ribbon Make service calls
- Use discovery client Make client calls
- Use loadBalanceClient Make client calls
- Use @loadBalanced Make client calls
# 3.1 Use discovery Client Form call
@Autowired
private DiscoveryClient discoveryClient;
// Get a list of services
List<ServiceInstance> products = discoveryClient.getInstances(" service ID");
for (ServiceInstance product : products) {
log.info(" Service host :[{}]",product.getHost());
log.info(" Service port :[{}]",product.getPort());
log.info(" Service address :[{}]",product.getUri());
log.info("====================================");
}
# 3.2 Use loadBalance Client Form call
@Autowired
private LoadBalancerClient loadBalancerClient;
// Select a service call according to the load balancing strategy
ServiceInstance product = loadBalancerClient.choose(" service ID");
log.info(" Service host :[{}]",product.getHost());
log.info(" Service port :[{}]",product.getPort());
log.info(" Service address :[{}]",product.getUri());
# 3.3 Use @loadBalanced
//1. Integrate restTemplate + ribbon
@Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
//2. Call service location injection RestTemplate
@Autowired
private RestTemplate restTemplate;
//3. call
String forObject = restTemplate.getForObject("http:// service ID/hello/hello?name=" + name, String.class);
版权声明
本文为[Leon_ Jinhai_ Sun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232157393835.html
边栏推荐
- NVM introduction, NVM download, installation and use (node version management)
- Introduction to hystrix and implementation of server fuse
- Tear the Google SRE book by hand
- MySQL 回表
- POI和EasyExcel讲解
- static关键字及应用
- Ribbon组件负载均衡调用和使用
- JS merge duplicate data in array object
- C language programming based on loop structure (PTA)
- Convert local pictures to Base64 encoding
猜你喜欢
Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
21. Basic usage of MariaDB
瑞萨IDE:CS+ for CC新建工程配置方法
LabVIEW modify the appearance of the application window
关于DateUtil时间工具类造成程序报错
On nanopi M1 (Quanzhi H3) kernel driver programming HelloWorld (compilation mode I)
Beijialai touch screen maintenance 4pp065 0571-X74F
Ribbon负载均衡策略
Idea import a project
JS prototype and prototype chain
随机推荐
OpenFeign之响应处理
2. GPIO control summary (kernel driver) of nanopi M1 (Quanzhi H3)
Beijialai touch screen maintenance 4pp065 0571-X74F
Database Experiment 2 data query
2022-04-24日報:在生物科學領域應用深度學習的當前進展和開放挑戰
MVC three-tier architecture (illustration)
The DNN of OpenCV is used to read onnx as the prediction end to realize classification
Convert local pictures to Base64 encoding
Understanding society at the age of 14 - reading notes for you who want to be a doctor
MySQL 回表
JS merge duplicate data in array object
LabVIEW modify the appearance of the application window
Ribbon组件负载均衡调用和使用
Handling of alternative solutions for openfeign integration with hystrix
瑞萨IDE:CS+ for CC下载、安装和基础使用
延时消息常见实现方案
LabVIEW显示控件中内容过长设置自动滚动条
QT QML component library records owned by QML except basic components
通过OpenFeign传递对象类型参数
consul 开启健康监控检查