springboot 3中远程调用方式

@Autowired
private LoadBalancerClient loadBalancerClient;
@Autowired
private RestTemplate restTemplate;
@GetMapping("/getProductMeg")
public String getProductMeg() {
//第一种远程调用
RestTemplate restTemplate = new RestTemplate();
String responese = restTemplate.getForObject(“http://localhost:8080//msg”, String.class);
log.info("responese{} ", responese);

    //第二种远程调用
   ServiceInstance serviceInstance = loadBalancerClient.choose("PRODUCT");
    String url = String.format("http://%s:%s", serviceInstance.getHost() + serviceInstance.getPort() + "/msg");
    log.info("url ", url);

    //第二种远程调用
    String url2 =  restTemplate.getForObject("http://PRODUCT/msg",String.class);
    log.info("url ", url2);
   return responese;

}

springboot 3中远程调用方式_第1张图片

你可能感兴趣的:(java)