Commit fa4d9700 by Dave Syer

Tweaks

parent cf615282
...@@ -8,16 +8,16 @@ import org.springframework.cloud.client.ServiceInstance; ...@@ -8,16 +8,16 @@ import org.springframework.cloud.client.ServiceInstance;
public interface LoadBalancerClient { public interface LoadBalancerClient {
/** /**
* Choose a {@see ServiceInstance} from the LoadBalancer for the specified service * Choose a {@see ServiceInstance} from the LoadBalancer for the specified service
* @param serviceId The serviceId to use to look up the LoadBalancer * @param serviceId the service id to look up the LoadBalancer
* @return * @return a ServiceInstance that matches the serviceId
*/ */
public ServiceInstance choose(String serviceId); public ServiceInstance choose(String serviceId);
/** /**
* Choose a {@see ServiceInstance} from the LoadBalancer for the specified service * Choose a {@see ServiceInstance} from the LoadBalancer for the specified service
* @param serviceId The serviceId to use to look up the LoadBalancer * @param serviceId the service id to look up the LoadBalancer
* @param request allows implementations to execute pre and post actions such as incrementing metrics * @param request allows implementations to execute pre and post actions such as incrementing metrics
* @return * @return the result of the LoadBalancerRequest callback on the selected ServiceInstance
*/ */
public <T> T choose(String serviceId, LoadBalancerRequest<T> request); public <T> T choose(String serviceId, LoadBalancerRequest<T> request);
} }
...@@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; ...@@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration; import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientPreprocessor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpRequestInterceptor;
...@@ -18,7 +17,9 @@ import org.springframework.web.client.RestTemplate; ...@@ -18,7 +17,9 @@ import org.springframework.web.client.RestTemplate;
import com.netflix.loadbalancer.BaseLoadBalancer; import com.netflix.loadbalancer.BaseLoadBalancer;
/** /**
* Auto configuration for Ribbon (client side load balancing)
* @author Spencer Gibb * @author Spencer Gibb
* @author Dave Syer
*/ */
@Configuration @Configuration
@AutoConfigureAfter(EurekaClientAutoConfiguration.class) @AutoConfigureAfter(EurekaClientAutoConfiguration.class)
...@@ -28,9 +29,8 @@ public class RibbonAutoConfiguration { ...@@ -28,9 +29,8 @@ public class RibbonAutoConfiguration {
private List<BaseLoadBalancer> balancers = Collections.emptyList(); private List<BaseLoadBalancer> balancers = Collections.emptyList();
@Autowired @Autowired
private EurekaRibbonClientPreprocessor clientPreprocessor; private RibbonClientPreprocessor clientPreprocessor;
// TODO: need to find a default for this?
@Autowired @Autowired
private SpringClientFactory springClientFactory; private SpringClientFactory springClientFactory;
...@@ -59,6 +59,7 @@ public class RibbonAutoConfiguration { ...@@ -59,6 +59,7 @@ public class RibbonAutoConfiguration {
protected static class DefaultRibbonClientPreprocessor { protected static class DefaultRibbonClientPreprocessor {
@Bean @Bean
@ConditionalOnMissingBean(RibbonClientPreprocessor.class)
public RibbonClientPreprocessor ribbonClientPreprocessor() { public RibbonClientPreprocessor ribbonClientPreprocessor() {
return new RibbonClientPreprocessor() { return new RibbonClientPreprocessor() {
@Override @Override
......
...@@ -26,6 +26,8 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient { ...@@ -26,6 +26,8 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
private Map<String, ILoadBalancer> balancers = new HashMap<String, ILoadBalancer>(); private Map<String, ILoadBalancer> balancers = new HashMap<String, ILoadBalancer>();
public RibbonLoadBalancerClient(RibbonClientPreprocessor ribbonClientPreprocessor, SpringClientFactory clientFactory, List<BaseLoadBalancer> balancers) { public RibbonLoadBalancerClient(RibbonClientPreprocessor ribbonClientPreprocessor, SpringClientFactory clientFactory, List<BaseLoadBalancer> balancers) {
this.ribbonClientPreprocessor = ribbonClientPreprocessor;
this.clientFactory = clientFactory;
for (BaseLoadBalancer balancer : balancers) { for (BaseLoadBalancer balancer : balancers) {
this.balancers.put(balancer.getName(), balancer); this.balancers.put(balancer.getName(), balancer);
} }
......
...@@ -3,12 +3,12 @@ package org.springframework.cloud.netflix.ribbon; ...@@ -3,12 +3,12 @@ package org.springframework.cloud.netflix.ribbon;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import com.netflix.client.AbstractLoadBalancerAwareClient; import com.netflix.client.AbstractLoadBalancerAwareClient;
import com.netflix.client.ClientException; import com.netflix.client.ClientException;
import com.netflix.client.IClient; import com.netflix.client.IClient;
import com.netflix.client.IClientConfigAware; import com.netflix.client.IClientConfigAware;
import lombok.extern.slf4j.Slf4j;
import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.DefaultClientConfigImpl; import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
...@@ -44,9 +44,9 @@ public class SpringClientFactory { ...@@ -44,9 +44,9 @@ public class SpringClientFactory {
"A Rest Client with this name is already registered. Please use a different name"); "A Rest Client with this name is already registered. Please use a different name");
} }
try { try {
String clientClassName = (String) clientConfig.getProperty(CommonClientConfigKey.ClientClassName); String clientClassName = (String) clientConfig.get(CommonClientConfigKey.ClientClassName);
client = (IClient<?, ?>) instantiateInstanceWithClientConfig(clientClassName, clientConfig); client = (IClient<?, ?>) instantiateInstanceWithClientConfig(clientClassName, clientConfig);
boolean initializeNFLoadBalancer = Boolean.parseBoolean(clientConfig.getProperty( boolean initializeNFLoadBalancer = Boolean.parseBoolean(clientConfig.get(
CommonClientConfigKey.InitializeNFLoadBalancer, DefaultClientConfigImpl.DEFAULT_ENABLE_LOADBALANCER).toString()); CommonClientConfigKey.InitializeNFLoadBalancer, DefaultClientConfigImpl.DEFAULT_ENABLE_LOADBALANCER).toString());
if (initializeNFLoadBalancer) { if (initializeNFLoadBalancer) {
loadBalancer = getNamedLoadBalancer(restClientName, clientConfig.getClass()); loadBalancer = getNamedLoadBalancer(restClientName, clientConfig.getClass());
...@@ -149,7 +149,7 @@ public class SpringClientFactory { ...@@ -149,7 +149,7 @@ public class SpringClientFactory {
} }
ILoadBalancer lb = null; ILoadBalancer lb = null;
try { try {
String loadBalancerClassName = (String) clientConfig.getProperty(CommonClientConfigKey.NFLoadBalancerClassName); String loadBalancerClassName = (String) clientConfig.get(CommonClientConfigKey.NFLoadBalancerClassName);
lb = (ILoadBalancer) instantiateInstanceWithClientConfig(loadBalancerClassName, clientConfig); lb = (ILoadBalancer) instantiateInstanceWithClientConfig(loadBalancerClassName, clientConfig);
namedLBMap.put(name, lb); namedLBMap.put(name, lb);
log.info("Client:" + name log.info("Client:" + name
......
...@@ -6,8 +6,8 @@ import static com.netflix.client.config.CommonClientConfigKey.NFLoadBalancerRule ...@@ -6,8 +6,8 @@ import static com.netflix.client.config.CommonClientConfigKey.NFLoadBalancerRule
import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListClassName; import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListClassName;
import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListFilterClassName; import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListFilterClassName;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor; import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import com.netflix.config.ConfigurationManager; import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext.ContextKey; import com.netflix.config.DeploymentContext.ContextKey;
......
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