当前位置:网站首页>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
边栏推荐
猜你喜欢
LabVIEW显示控件中内容过长设置自动滚动条
Siemens CNC machine tool maintenance panel 1af5200a2-840a
[LeetCode][Golang] 647. 回文子串
Cancel the default open project setting of idea
hystrix dashboard的使用
leetcode 2223 — 构造字符串的总得分和
开发consul 客户端即微服务
DW basic tutorial (I)
服务间通信和RestTemplate完成服务间通信
Mixed use of Oracle column row conversion and comma truncated string
随机推荐
A method of asynchronous response of application service through load balancing
Easylaser laser shaft alignment instrument maintenance homocentric instrument maintenance E420
LabVIEW修改应用程序窗口外观
Mixed use of Oracle column row conversion and comma truncated string
Mobile phone uses SSH to log in nanopi M1 summary (this time on the same LAN)
OpenFeign 组件说明
static关键字及应用
Introduction to hystrix and implementation of server fuse
CVPR2022 | 基于知识蒸馏的高效预训练
Tear the Google SRE book by hand
Database experiment I database definition and data import
Beijialai touch screen maintenance 4pp065 0571-X74F
ERP function_ Financial management_ Basic concepts of Finance
Database Experiment 5 Security Language Experiment
Renesas ide: CS + for CC download, installation and basic use
Convert pictures on OSS to Base64 encoding
Hystrix简介和服务端熔断的实现
LabVIEW采集鼠标、键盘数据
Member and non member functions
OpenFeign的参数传递之数组和集合类型