当前位置:网站首页>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
边栏推荐
- How to use the project that created SVN for the first time
- MVC three-tier architecture (illustration)
- Vscode may not establish connection to "XXX"
- Ribbon停止维护
- Unity makes a small planet
- Ribbon组件负载均衡调用和使用
- UML learning reprint
- Oracle intercepts special characters
- OpenFeign的参数传递之数组和集合类型
- Spellman high voltage power supply maintenance xrm50p50x3768 power supply maintenance pcm70n120x451
猜你喜欢

在线时序流程图制作工具

Easylaser laser shaft alignment instrument maintenance homocentric instrument maintenance E420

Online Excel to CSV tool

On nanopi M1 (Quanzhi H3) kernel driver programming HelloWorld (compilation mode I)

About the program error caused by dateutil time tool class

C reads excel specific data into specific columns of DataGridView

Maintenance of coherent PMB power supply of rofin laser hpc840

Leetcode 2223 -- sum of total scores of construction string

Based on jsplumb JS to achieve multi list one to many connection effect

Code cloud download history version process
随机推荐
Database Experiment four View experiment
ERP function_ Financial management_ Basic concepts of Finance
QT QML component library records owned by QML except basic components
MySQL back to table
服务雪崩、服务熔断、服务降级
2022 - 04 - 24 Daily: Current Progress and Open Challenges of Applied Deep Learning in Biological Sciences
Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
[LeetCode][Golang] 647. 回文子串
瑞萨IDE:CS+ for CC新建工程配置方法
Five cool login pages that can be used
Download, install and configure Huawei integrated development environment ide deveco device tool
资本追逐Near生态
OpenFeign之响应处理
上海确保疫情保供生活物资质量和食品安全
Ribbon负载均衡策略
OpenFeign的细节展示
When pycharm debugs, view the tensor image of pytorch in the console
How to use the project that created SVN for the first time
Unity制作一个小星球
OpenFeign的参数传递之数组和集合类型