欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OpenFeign

程序员文章站 2024-02-14 12:34:04
...

简单记录一下open Feign的用法

1.添加依赖,
2.在启动类上添加注解:@EnableFeignClients

3.创建服务类----用于调用远程服务

@Component
@FeignClient("PAYMENT")  //要调用的服务名
public interface PaymentFeignService {
//远程服务的handler
@RequestMapping("payment/query")
@ResponseBody
CommonResult<Payment> query(@RequestBody Long id);

@RequestMapping("test")
@ResponseBody
void test();
}

4.业务类中调用

@Resource
PaymentFeignService paymentFeignService;

@RequestMapping("/test")
@ResponseBody
public CommonResult<Payment> test(){
System.out.println("feign here ");
paymentFeignService.test();
return null;
}

超时控制

ribbon:
    ReadTimeout = 5000
    ConnectTimeout = 5000

日志增强

@Bean
Logger.Level feignLoggerLevel(){
    return Logger.Level.FULL;
}

设置监听接口的级别

logging:
  level:
    org.yuanqi.customerfeign83.service.PaymentFeignService: debug
相关标签: OpenFeign