微服务——服务之间访问,用Feign请求服务接口超时如何解决?
在Feign配置文件类中设置超时时间:
package com.changgou.goods.pojo; import feign.Request; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; @Component public class FeignClientConfig { // 连接超时 @Value("${service.feign.connectTimeout:60000}") private int connectTimeout; // 数据读取超时 @Value("${service.feign.readTimeOut:60000}") private int readTimeout; // 构造自定义配置类 @Bean public Request.Options options() { return new Request.Options(connectTimeout, readTimeout); } }
然后在对外开放的Feign接口注解上加上配置类
configuration = FeignClientConfig.class
@FeignClient(value = "goods",configuration = FeignClientConfig.class) @RequestMapping("/sku") public interface SkuFeign {}