(1)在8001服务提供方的controller里面定义一个方法
这个方法就是故意模拟一个调用时间超时的方法
//故意模拟服务超时
@GetMapping("/payment/feign/timeout")
public String paymentFeignTimeOut(){
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
return “time out…”;
}
(2)在feign客户端PaymentFeignService里面定义
@GetMapping("/payment/feign/timeout")
public String paymentFeignTimeOut();
(3)在controller类CustomerFeignController里面定义
@GetMapping(“consumer/feign/timeout”)
public String timeout(){
//openfeign调用服务,默认等待时间是1秒钟
return paymentFeignService.paymentFeignTimeOut();
}
(4)测试
首先我们直接访问8001服务中的paymentFeignTimeOut方法
然后我们通过feign客户端类访问
为了避免