微服务——服务之间访问,用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 {}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM