spring boot/spring cloud 远程调用解决方案

1.feign的远程调用(http接口调用)

     ①pom.xml配置

   
      org.springframework.cloud
      spring-cloud-starter-openfeign
   

    ②启动类application 注解@EnableFeignClients,可选择用ribbon作为服务端的负载均衡和超时重连;

   hystrix做熔断(需注意,为避免重连被熔断,所以熔断时间应大于重连时间):yml文件配置

 search-record:
   ribbon:
     listOfServers: http://127.0.0.1:12100
 ribbon:
    ReadTimeout: 60000
    ConnectTimeout: 60000
 hystrix:
   command:
     default:
       execution:
         isolation:
          thread:
            timeoutInMilliseconds: 60000

    ③配置接口类

  类注解 @FeignClient("search-record")

   类似控制层的接口发布:

    

@PostMapping("/schedule/data/{medicalCaseId}")
JsonResult scheduleMedicalCase(@PathVariable("medicalCaseId")String medicalCaseId,
                               @RequestParam("systemType") Integer systemType,
                               @RequestParam("clientId") Integer clientId);

▲只要在方法中调用feignClient的方法名(如XXX.scheduleMedicalCase(medicalCaseId,systemType,clientId))

即可实现远程调用,较为轻便。和方法调用一致。

 

你可能感兴趣的:(spring,cloud)