spring cloud 的Feign 的使用

1. 开启feign:在application启动类上添加注解@EnableFeignClients(basePackages = ("com.spring.feign"))

2. Feign 的请求时间间隔及次数配置

@Configuration
public class FeignConfig {

    // period=3000 发起当前请求的时间间隔,单位毫秒
    // maxPeriod=5s 发起当前请求的最大时间间隔,单位毫秒
    // maxAttempts=5 最多请求次数,包括第一次
    @Bean
    public Retryer feignRetryer(){
        return new Retryer.Default(3000,TimeUnit.SECONDS.toMillis(5),5);
    }
}

3. 设置feign readTimeout and connectTimeout,时间单位是毫秒

#timeout setup for feign client connect/read service provider
feign.client.config.default.connectTimeout = 9000
feign.client.config.default.readTimeout = 60000

参考:
https://www.jianshu.com/p/8bca50cb11d8

猜你喜欢

转载自www.cnblogs.com/wanthune/p/12024003.html