如何在springBoot中进行ReactiveFeignClient超时配置

最近项目中用到了ReactiveFeign请求第三方的http接口,需要自定义一个请求超时时间,但在网上查了很多资料都没有一个比较准确的配置方法。

  • pom依赖
  • <dependency>
    <groupId>com.playtika.reactivefeign</groupId>
    <artifactId>3.2.1</artifactId>
    <type>pom</type>
    </dependency>

     

  • application.yml配置自定义参数值,参数名根据自己需要命名即可,此处需按ym格式书写即可
  • ReactiveFeignClient:
     writeTimeout: 1000
     readTimeout: 1000
     connectTimeout: 1000

     

  • 编写一个配置类ReactiveFeignConfig.java
  • @Configuration
    public class ReactiveFeignConfig{
    
      @Value("${ReactiveFeignClient.readTimeout}")
      private int readTimeout;
    
      @Value("${ReactiveFeignClient.writeTimeout}")
      private int writeTimeout;
    
      @Value("${ReactiveFeignClient.connectTimeout}")
      private int connectTimeout; 
    
    
      @Bean
       public ReactiveOptions reactiveOptions(){
         return new 
    WebReactiveOptions.Builder().setWriteTimeoutMillis(this.readTimeout).setReadTimeoutMillis(this.readTimeout).setConnectTimeoutMillis(this.connectTimeout).build();
         }
    }
      
    
      
      

     

  • 在启动类中增加注解:@EnableReactiveFeignClients 

  • 经测试配置生效
posted @ 2022-08-30 09:49  陈浩文  阅读(790)  评论(0编辑  收藏  举报