当前位置:网站首页>Resttemplate service call
Resttemplate service call
2022-04-23 22:10:00 【Leon_ Jinhai_ Sun】
# 1. Create two services and register to consul In the registry
- users Service on behalf of users Port is 9999
- products On behalf of goods and services Port is 9998
` Be careful : The service here is just for testing , There is no practical business significance


# 2. Service method in commodity service @RestController
@Slf4j
public class ProductController {
@Value("${server.port}")
private int port;
@GetMapping("/product/findAll")
public Map<String,Object> findAll(){
log.info(" Commodity service query all calls succeeded , Current service port :[{}]",port);
Map<String, Object> map = new HashMap<String,Object>();
map.put("msg"," Service call succeeded , The service provider port is : "+port);
map.put("status",true);
return map;
}
}# 3. Use in user services restTemplate To call @RestController
@Slf4j
public class UserController {
@GetMapping("/user/findAll")
public String findAll(){
log.info(" Call the user service ...");
//1. Use restTemplate Call commodity service
RestTemplate restTemplate = new RestTemplate();
String forObject = restTemplate.getForObject("http://localhost:9998/product/findAll",
String.class);
return forObject;
}
}# 4. Start the service 
# 5. Test service invocation
- Browser access to user services http://localhost:9999/user/findAll # 6. summary
- rest Template It is called directly based on the service address, and the service is not obtained in the service registry , There is no way to achieve service load balancing. If you need to achieve service load balancing, you need to write your own service load balancing strategy .
版权声明
本文为[Leon_ Jinhai_ Sun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232157394049.html
边栏推荐
- openfeign集成Hystrix的备选方案处理
- Hystrix组件
- Openharmony get the source code
- Five cool login pages that can be used
- Database experiment VI integrity language experiment
- LabVIEW修改应用程序窗口外观
- Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
- Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
- 2. GPIO control summary (kernel driver) of nanopi M1 (Quanzhi H3)
- Hirschmann display maintenance computer controller repair
猜你喜欢

RestTemplate 服务调用

SSH in win10

Cancel the default open project setting of idea

21. Basic usage of MariaDB

Database experiment VI integrity language experiment

Mobile phone uses SSH to log in nanopi M1 summary (this time on the same LAN)
![[LeetCode][Golang] 647. 回文子串](/img/99/46628e46a068594aad77f2707e2964.jpg)
[LeetCode][Golang] 647. 回文子串

分布式系统服务熔断

瑞萨IDE:CS+ for CC新建工程配置方法

Spellman high voltage power supply maintenance xrm50p50x3768 power supply maintenance pcm70n120x451
随机推荐
C winfrom DataGridView click on the column header can not automatically sort the problem
2022 - 04 - 24 Daily: Current Progress and Open Challenges of Applied Deep Learning in Biological Sciences
Leetcode 2223 -- sum of total scores of construction string
基于Ribbon的服务调用
UML学习转载
基于RestTemplate的服务调用
LabVIEW修改应用程序窗口外观
服务熔断的实现
延时消息常见实现方案
Capital chasing near ecology
Lightweight project management ideas
LabVIEW sets the transparency of the application display label
瑞萨IDE:CS+ for CC下载、安装和基础使用
从严从重从快 上海全面加强疫情期间食品安全监管
Pytorch deep learning practice (2)
关于DateUtil时间工具类造成程序报错
Convert local pictures to Base64 encoding
修改服务的默认负载均衡策略
21. Basic usage of MariaDB
MySQL back to table