1、Feign配置
@Configuration
public class FeignConfig {
@Value("${coupon_service.url:http://localhost:8081}")
private String couponServiceUrl;
@Bean
public CouponQueryServiceApi queryCouponServiceApi() {
// connectTimeoutMillis=5*1000 链接超时时间
// readTimeoutMillis=10*1000 响应超时时间,如果超过10秒没有接过发起下一次请求
Request.Options options = new Request.Options(5 * 1000, 10 * 1000);
// period=100 发起当前请求的时间间隔,单位毫秒
// maxPeriod=1000 发起当前请求的最大时间间隔,单位毫秒
// maxAttempts=5 最多请求次数,包括第一次
Retryer neverRetry = new Retryer.Default(100, 1000, 5);
return Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.options(options)
.retryer(neverRetry)
.target(CouponQueryServiceApi.class, couponServiceUrl);
}
} <