eureka功能区集成 - 无法列出服务器

时间:2017-01-24 12:53:00

标签: java spring-boot netflix-eureka netflix-ribbon

当我尝试执行以下使用功能区的代码并尝试从eureka获取服务器列表时,我收到以下异常。

异常

3122 [main] WARN com.netflix.loadbalancer.RoundRobinRule - No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=origin,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:DiscoveryEnabledNIWSServerList:; clientName:origin; Effective vipAddresses:localhost; isSecure:false; datacenter:null
Exception in thread "main" com.netflix.client.ClientException: LoadBalancer returned null Server for :origin
    at com.netflix.client.LoadBalancerContext.computeFinalUriWithLoadBalancer(LoadBalancerContext.java:418)
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:166)
    at com.netflix.zuul.RibbonTest.main(RibbonTest.java:23)

代码

public static void main(String[] args) throws Exception {
    ConfigurationManager.loadPropertiesFromResources("ribbon-client.properties");
    RestClient client = (RestClient) ClientFactory.getNamedClient("origin");          
    HttpRequest request = HttpRequest.newBuilder().uri(new URI("/serviceContext/api/v1/")).build(); 
    for (int i = 0; i < 20; i++)  {
        HttpResponse response = client.executeWithLoadBalancer(request); 
    }
}

ribbon-client.properties

origin.ribbon.NIWSServerListClassName=com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
#also tried unsuccessfully with localhost:8091, localhost:8091/serviceContext
origin.ribbon.DeploymentContextBasedVipAddresses=localhost

该服务是使用eureka-client.properties的Spring-Boot(不使用Spring-Cloud)应用程序:

eureka-client.properties

eureka.registration.enabled=true
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:9080/eureka/v2/
eureka.region=default
eureka.name=service-Eureka
eureka.vipAddress=localhost
eureka.port=8091
eureka.instanceId=CHNSHL119363L

该服务已在本地tomcat @ port 9080中部署的eureka成功注册,并且可以发现@ http://localhost:9080/eureka/ and http://localhost:9080/eureka/v2/apps/

使用Spring-Cloud的W / O需要在上面的代码/配置中修复哪些内容才能使用功能区从eureka动态获取服务器列表?

1 个答案:

答案 0 :(得分:0)

以下post有用。 这个问题由解决了 1.更正服务和功能区的vipAddress配置
2.配置并注册功能区为eureka-client

<强> 1。 vipAddress的更改

eureka-client.properties(service)

eureka.vipAddress = my.eureka.local

ribbon-client.properties

origin.ribbon.DeploymentContextBasedVipAddresses = my.eureka.local

<强> 2。将功能区注册为eureka-client

的更改
public static void main(String[] args) throws Exception {
    ConfigurationManager.loadPropertiesFromResources("ribbon-client.properties");

    **InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
    applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
    eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig);**

    RestClient client = (RestClient) ClientFactory.getNamedClient("origin");          
    HttpRequest request = HttpRequest.newBuilder().uri(new URI("/serviceContext/api/v1/")).build(); 
    for (int i = 0; i < 20; i++)  {
                HttpResponse response = client.executeWithLoadBalancer(request); 
    }
}