Feign OkHttp client configuration
This commit is contained in:
committed by
Spencer Gibb
parent
22f4b82efa
commit
966e03ba64
10
pom.xml
10
pom.xml
@@ -286,6 +286,11 @@
|
||||
<artifactId>feign-hystrix</artifactId>
|
||||
<version>${feign.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.feign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
<version>${feign.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.hystrix</groupId>
|
||||
<artifactId>hystrix-core</artifactId>
|
||||
@@ -363,6 +368,11 @@
|
||||
<artifactId>spring-integration-java-dsl</artifactId>
|
||||
<version>${spring-integration-dsl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
||||
@@ -116,6 +116,11 @@
|
||||
<artifactId>feign-hystrix</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.feign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.hystrix</groupId>
|
||||
<artifactId>hystrix-core</artifactId>
|
||||
@@ -176,6 +181,11 @@
|
||||
<artifactId>jersey-apache-client4</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.netflix.loadbalancer.ILoadBalancer;
|
||||
import feign.Client;
|
||||
import feign.Feign;
|
||||
import feign.httpclient.ApacheHttpClient;
|
||||
import feign.okhttp.OkHttpClient;
|
||||
|
||||
/**
|
||||
* Autoconfiguration to be activated if Feign is in use and needs to be use Ribbon as a
|
||||
@@ -81,4 +82,28 @@ public class FeignRibbonClientAutoConfiguration {
|
||||
return new LoadBalancerFeignClient(delegate, this.cachingFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(OkHttpClient.class)
|
||||
@ConditionalOnProperty(value = "feign.okhttp.enabled", matchIfMissing = true)
|
||||
protected static class OkHttpConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private com.squareup.okhttp.OkHttpClient okHttpClient;
|
||||
|
||||
@Autowired
|
||||
CachingSpringLoadBalancerFactory cachingFactory;
|
||||
|
||||
@Bean
|
||||
public Client feignClient() {
|
||||
OkHttpClient delegate;
|
||||
if (this.okHttpClient != null) {
|
||||
delegate = new OkHttpClient(this.okHttpClient);
|
||||
}
|
||||
else {
|
||||
delegate = new OkHttpClient();
|
||||
}
|
||||
return new LoadBalancerFeignClient(delegate, this.cachingFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ import feign.RequestTemplate;
|
||||
@WebIntegrationTest(randomPort = true, value = {
|
||||
"spring.application.name=feignclienttest",
|
||||
"logging.level.org.springframework.cloud.netflix.feign.valid=DEBUG",
|
||||
"feign.httpclient.enabled=false"})
|
||||
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false"})
|
||||
@DirtiesContext
|
||||
public class FeignClientTests {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user