2

リボンを使用して 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); 
    }
}

リボン クライアント.プロパティ

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

このサービスは、以下を使用する Spring-Boot (Spring-Cloud を使用しない) アプリです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

サービスは、ローカルの tomcat@port 9080 にデプロイされた eureka に正常に登録され、発見可能です @http://localhost:9080/eureka/ and http://localhost:9080/eureka/v2/apps/

Spring-Cloud を使用せずに、リボンを使用して eureka からサーバーのリストを動的に取得できるようにするには、上記のコード/構成で何を修正する必要がありますか?

4

1 に答える 1