Commit bb5fdd9e authored by 郑航's avatar 郑航

Feign客户端支持配置化

parent 7be203a3
......@@ -29,6 +29,7 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
......@@ -38,6 +39,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
......@@ -294,10 +296,29 @@ public class BraveAutoConfiguration {
}
@Configuration
@DependsOn(value = "techOkHttpClient")
@ConditionalOnClass(EnableFeignClients.class)
@ConditionalOnProperty(prefix = "tech.brave", name = "enabled", havingValue = "true", matchIfMissing = true)
public static class FeignReplaceWithOkhttp {
@Value("feign.maxIdleConnections:100")
private Integer maxIdleConnections;
@Value("feign.keepAliveDuration:5")
private Integer keepAliveDuration;
@Value("feign.readtimeout:1")
private Integer readTimeOut;
@Value("feign.writeTimeout:1")
private Integer writeTimeout;
@Value("feign.connectTimeout:1")
private Integer connectTimeout;
@Value("feign.retryOnConnectionFailure:true")
private Boolean retryOnConnectionFailure;
@Autowired
private ITechOkHttpClient techOkHttpClient;
......@@ -319,11 +340,11 @@ public class BraveAutoConfiguration {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
okHttpClientBuilder.addInterceptor(httpLoggingInterceptor)
.connectionPool(new ConnectionPool(100,5, TimeUnit.MINUTES))
.readTimeout(1, TimeUnit.SECONDS)
.writeTimeout(1,TimeUnit.SECONDS)
.connectTimeout(1,TimeUnit.SECONDS)
.retryOnConnectionFailure(true);
.connectionPool(new ConnectionPool(maxIdleConnections,keepAliveDuration, TimeUnit.MINUTES))
.readTimeout(readTimeOut, TimeUnit.SECONDS)
.writeTimeout(writeTimeout,TimeUnit.SECONDS)
.connectTimeout(connectTimeout,TimeUnit.SECONDS)
.retryOnConnectionFailure(retryOnConnectionFailure);
return okHttpClientBuilder.build();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment