在主启动类中
//激活并开启FeignClient的注解
@EnableFeignClients
@Component
@FeignClient("CLOUD-PAYMENT-SERVICE")//对应远程调用的注册服务中心的注册名
public interface PaymentFeignService {@GetMapping("/payment/get/{id}")//对应远程调用的方法名public CommonResult getPaymentById(@PathVariable("id") Long id);
}
//直接使用即可@Resourceprivate PaymentFeignService paymentFeignService;@GetMapping("/consumer/payment/get/{id}")public CommonResult getPaymentByID(@PathVariable("id") Long id){return paymentFeignService.getPaymentById(id);}
ribbon:
##指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的时间
ReadTimeout: 5000
##指的是建立连接后从服务器读取到可用资源所用的时间
ConnectTimeout: 5000
日志打印:
写配置bean
在yml文件中:
logging:
level:
//feign日志以什么级别监控哪个接口com.atguigu.springcloud.service.PaymentFeignService: debug