Commit ab563a1e by Nepxion

优化Eureka层面的逻辑

parent 2886064c
...@@ -15,17 +15,17 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,17 +15,17 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.cloud.netflix.ribbon.PropertiesFactory; import org.springframework.cloud.netflix.ribbon.PropertiesFactory;
import org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList;
import org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration; import org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration;
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.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.decorator.DiscoveryEnabledNIWSServerListDecorator; import com.nepxion.discovery.plugin.framework.decorator.EurekaServerListDecorator;
import com.nepxion.discovery.plugin.framework.listener.loadbalance.LoadBalanceListenerExecutor; import com.nepxion.discovery.plugin.framework.listener.loadbalance.LoadBalanceListenerExecutor;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.discovery.EurekaClient; import com.netflix.discovery.EurekaClient;
import com.netflix.loadbalancer.ServerList; import com.netflix.loadbalancer.ServerList;
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
@Configuration @Configuration
@AutoConfigureAfter(EurekaRibbonClientConfiguration.class) @AutoConfigureAfter(EurekaRibbonClientConfiguration.class)
...@@ -51,12 +51,12 @@ public class EurekaLoadBalanceConfiguration { ...@@ -51,12 +51,12 @@ public class EurekaLoadBalanceConfiguration {
return this.propertiesFactory.get(ServerList.class, config, serviceId); return this.propertiesFactory.get(ServerList.class, config, serviceId);
} }
DiscoveryEnabledNIWSServerListDecorator discoveryServerList = new DiscoveryEnabledNIWSServerListDecorator(config, eurekaClientProvider); DiscoveryEnabledNIWSServerList discoveryServerList = new DiscoveryEnabledNIWSServerList(config, eurekaClientProvider);
discoveryServerList.setEnvironment(environment);
discoveryServerList.setLoadBalanceListenerExecutor(loadBalanceListenerExecutor);
discoveryServerList.setServiceId(config.getClientName());
DomainExtractingServerList serverList = new DomainExtractingServerList(discoveryServerList, config, this.approximateZoneFromHostname); EurekaServerListDecorator serverList = new EurekaServerListDecorator(discoveryServerList, config, this.approximateZoneFromHostname);
serverList.setEnvironment(environment);
serverList.setLoadBalanceListenerExecutor(loadBalanceListenerExecutor);
serverList.setServiceId(config.getClientName());
return serverList; return serverList;
} }
......
...@@ -11,45 +11,24 @@ package com.nepxion.discovery.plugin.framework.decorator; ...@@ -11,45 +11,24 @@ package com.nepxion.discovery.plugin.framework.decorator;
import java.util.List; import java.util.List;
import javax.inject.Provider; import org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware; import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.listener.loadbalance.LoadBalanceListenerExecutor; import com.nepxion.discovery.plugin.framework.listener.loadbalance.LoadBalanceListenerExecutor;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.discovery.EurekaClient; import com.netflix.loadbalancer.ServerList;
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer; import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
public class DiscoveryEnabledNIWSServerListDecorator extends DiscoveryEnabledNIWSServerList { public class EurekaServerListDecorator extends DomainExtractingServerList {
private ConfigurableEnvironment environment; private ConfigurableEnvironment environment;
private LoadBalanceListenerExecutor loadBalanceListenerExecutor; private LoadBalanceListenerExecutor loadBalanceListenerExecutor;
private String serviceId; private String serviceId;
@Deprecated public EurekaServerListDecorator(ServerList<DiscoveryEnabledServer> list, IClientConfig clientConfig, boolean approximateZoneFromHostname) {
public DiscoveryEnabledNIWSServerListDecorator() { super(list, clientConfig, approximateZoneFromHostname);
super();
}
@Deprecated
public DiscoveryEnabledNIWSServerListDecorator(String vipAddresses) {
super(vipAddresses);
}
@Deprecated
public DiscoveryEnabledNIWSServerListDecorator(IClientConfig clientConfig) {
super(clientConfig);
}
public DiscoveryEnabledNIWSServerListDecorator(String vipAddresses, Provider<EurekaClient> eurekaClientProvider) {
super(vipAddresses, eurekaClientProvider);
}
public DiscoveryEnabledNIWSServerListDecorator(IClientConfig clientConfig, Provider<EurekaClient> eurekaClientProvider) {
super(clientConfig, eurekaClientProvider);
} }
@Override @Override
......
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