疯狂的狮子li
2021-11-01 c4e17ff8472fd9f8123e86b593b2968ad5936b15
ruoyi-framework/src/main/java/com/ruoyi/framework/config/FeignConfig.java
@@ -1,7 +1,6 @@
package com.ruoyi.framework.config;
import feign.*;
import feign.hystrix.HystrixFeign;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
@@ -18,7 +17,9 @@
 * openfeign配置类
 *
 * @author Lion Li
 * @deprecated 由于使用人数较少 决定与 3.4.0 版本移除
 */
@Deprecated
@EnableFeignClients("${feign.package}")
@Configuration
@ConditionalOnClass(Feign.class)
@@ -33,11 +34,6 @@
                .writeTimeout(120, TimeUnit.SECONDS)
                .connectionPool(new ConnectionPool())
                .build();
    }
    @Bean
    public Feign.Builder feignBuilder() {
        return HystrixFeign.builder();
    }
    @Bean
@@ -60,4 +56,40 @@
        return new Retryer.Default();
    }
}
//   /**
//    * 自定义异常解码器
//    * 用于自定义返回体异常熔断
//    */
//   @Bean
//   public ErrorDecoder errorDecoder() {
//      return new CustomErrorDecoder();
//   }
//
//
//   /**
//    * 自定义返回体解码器
//    */
//   @Slf4j
//   public static class CustomErrorDecoder implements ErrorDecoder {
//
//      @Override
//      public Exception decode(String methodKey, Response response) {
//         Exception exception = null;
//         try {
//            // 获取原始的返回内容
//            String json = JsonUtils.toJsonString(response.body().asReader(StandardCharsets.UTF_8));
//            exception = new RuntimeException(json);
//            // 将返回内容反序列化为Result,这里应根据自身项目作修改
//            AjaxResult result = JsonUtils.parseObject(json, AjaxResult.class);
//            // 业务异常抛出简单的 RuntimeException,保留原来错误信息
//            if (result.getCode() != 200) {
//               exception = new RuntimeException(result.getMsg());
//            }
//         } catch (IOException e) {
//            log.error(e.getMessage(), e);
//         }
//         return exception;
//      }
//   }
}