Ensure SpringClientFactory gets used for Feign clients
If the ClientFactory from netflix is used directly it bypasses all the goodness in SpringClientFactory, so clients created in Feign before this change were getting the default native configuration instead of that provided by RibbonClientConfiguration. There are no remaining references to the raw ClientFactory in Spring Cloud, so we probably have seen the last of this. Fixes gh-118
This commit is contained in:
@@ -4,9 +4,11 @@ import feign.Client;
|
||||
import feign.Contract;
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.netflix.feign.ribbon.FeignRibbonClient;
|
||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
|
||||
@@ -46,8 +48,8 @@ public class FeignAutoConfiguration {
|
||||
@Configuration
|
||||
protected static class RibbonClientConfiguration {
|
||||
@Bean
|
||||
public Client feignRibbonClient() {
|
||||
return new FeignRibbonClient();
|
||||
public Client feignRibbonClient(SpringClientFactory factory) {
|
||||
return new FeignRibbonClient(factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.netflix.client.ClientException;
|
||||
import com.netflix.client.ClientFactory;
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.ILoadBalancer;
|
||||
|
||||
@@ -36,8 +37,13 @@ public class FeignRibbonClient implements Client {
|
||||
return HttpsURLConnection.getDefaultHostnameVerifier();
|
||||
}
|
||||
});
|
||||
private SpringClientFactory factory;
|
||||
|
||||
@Override
|
||||
public FeignRibbonClient(SpringClientFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) throws IOException {
|
||||
try {
|
||||
|
||||
@@ -56,8 +62,8 @@ public class FeignRibbonClient implements Client {
|
||||
}
|
||||
|
||||
private RibbonLoadBalancer lbClient(String clientName) {
|
||||
IClientConfig config = ClientFactory.getNamedConfig(clientName);
|
||||
ILoadBalancer lb = ClientFactory.getNamedLoadBalancer(clientName);
|
||||
IClientConfig config = factory.getClientConfig(clientName);
|
||||
ILoadBalancer lb = factory.getLoadBalancer(clientName);
|
||||
return new RibbonLoadBalancer(defaultClient, lb, config);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,15 @@ public class SpringClientFactory implements DisposableBean, ApplicationContextAw
|
||||
return getInstance(name, ILoadBalancer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client config associated with the name.
|
||||
*
|
||||
* @throws RuntimeException if any error occurs
|
||||
*/
|
||||
public IClientConfig getClientConfig(String name) {
|
||||
return getInstance(name, IClientConfig.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the load balancer context associated with the name.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user