当我尝试执行以下使用功能区的代码并尝试从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
该服务是使用eureka-client.properties
的Spring-Boot(不使用Spring-Cloud)应用程序:
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/
答案 0 :(得分:0)
以下post有用。
这个问题由解决了
1.更正服务和功能区的vipAddress配置
2.配置并注册功能区为eureka-client
<强> 1。 vipAddress的更改
eureka.vipAddress = my.eureka.local
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); } }