Commit fa4d9700 by Dave Syer

Tweaks

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