首页 > 其他 > 详细

解决openFeign超时的异常

时间:2021-06-28 10:00:52      阅读:56      评论:0      收藏:0      [点我收藏+]

1.异常信息

使用openFeign远程调用时出现如下异常

feign.RetryableException: Read timed out executing GET http://service-user/...

2.原因

因为默认时间太短,我们可以配置连接时间

3.解决方法

编写配置类:

package com.gh.config;

import feign.Request;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author Eric
 * @Date 2021/6/27 17:27
 * @Version 1.0
 */
@Configuration
public class ServiceFeignConfiguration {
    @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);
    }
}

在远程调用时使用配置类:

例如:

package com.gh.client;

import com.gh.config.ServiceFeignConfiguration;
import com.gh.model.user.Patient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @Author Eric
 * @Date 2021/6/26 16:32
 * @Version 1.0
 */
@Component
@FeignClient(value="service-user",configuration = ServiceFeignConfiguration.class)
public interface PatientFeignClient {

    @GetMapping("/api/user/patient/inner/get/{id}")
    public Patient getPatientById(@PathVariable("id") Long id);
}

 

解决openFeign超时的异常

原文:https://www.cnblogs.com/fqh2020/p/14942016.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!