2

I am getting the following exception when I am trying to execute the following code that uses ribbon and tries to get server list from eureka.

Exception

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)

Code

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

The service is a Spring-Boot (not using Spring-Cloud) app using eureka-client.properties:

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

The service gets registered successfully with eureka deployed in local tomcat@port 9080 and is discover-able @ http://localhost:9080/eureka/ and http://localhost:9080/eureka/v2/apps/

W/O using Spring-Cloud what needs to be fixed in the above code/configuration to be able to get list of servers dynamically from eureka using ribbon?

Divs
  • 1,578
  • 2
  • 24
  • 51

1 Answers1

0

The following post served useful. The issue is solved by
1. Correcting vipAddress configuration for service and ribbon
2. Configuring and registering ribbon as eureka-client

1. Changes for vipAddress

eureka-client.properties (service)

eureka.vipAddress=my.eureka.local

ribbon-client.properties

origin.ribbon.DeploymentContextBasedVipAddresses=my.eureka.local

2. Changes to register ribbon as 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); 
    }
}
Divs
  • 1,578
  • 2
  • 24
  • 51