1.服务productservices

@RestController
public class ProductController {
    @RequestMapping("/product/findAll")
    public Map findAll(){
        Map map = new HashMap();
        map.put("111","苹果手机");
        map.put("222","苹果笔记本");
        return map;
    }
}

 2.服务userservices

@RestController
public class UserController {

    @RequestMapping("/user/showProductMsg")
    public String showProductMsg(){
        RestTemplate restTemplate = new RestTemplate();
        String msg = restTemplate.getForObject("http://127.0.0.1:9001/product/findAll",String.class);
        return msg;
    }
}

 3.问题

1.直接使用restTemplate方式调用没有经过服务注册中心获取服务地址,代码写死不利于维护,当服务宕机时不能高效剔除。
2.调用服务时没有负载均衡需要自己实现负载均衡策略。

相关文章:

  • 2021-12-13
  • 2021-12-06
  • 2021-12-14
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
猜你喜欢
  • 2021-07-04
  • 2021-12-29
  • 2022-01-11
  • 2022-12-23
  • 2021-08-07
  • 2021-07-12
  • 2021-09-19
相关资源
相似解决方案