我用Ribbon和Netflix Eureka创建了一个简单的项目。 Eureka工作正常,我可以看到所有注册的服务。但是,功能区负载均衡器无法查看服务。实际上在日志中它打印出它在服务器中看到的服务器"当前的服务器列表"但是我得到的例外是没有找到的实例。我会非常感谢一些提示,我花了很多时间(和几天)来弄明白。
日志(我用<MY_IP>
替换了我的IP):
2017-10-14 18:13:18.118 INFO 6417 --- [nio-8080-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client:reservationManagement instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=reservationManagement,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2017-10-14 18:13:18.123 INFO 6417 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater
2017-10-14 18:13:18.165 INFO 6417 --- [nio-8080-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: reservationManagement.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2017-10-14 18:13:18.474 INFO 6417 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client reservationManagement initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=reservationManagement,current list of Servers=[<MY_IP>:8082],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:<MY_IP>:8082; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 01:00:00 CET 1970; First connection made: Thu Jan 01 01:00:00 CET 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
2017-10-14 18:13:18.634 WARN 6417 --- [nio-8080-exec-1] com.netflix.loadbalancer.RoundRobinRule : No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=reservationManagement,current list of Servers=[<MY_IP>:8082],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:<MY_IP>:8082; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 01:00:00 CET 1970; First connection made: Thu Jan 01 01:00:00 CET 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@1fd42bb7
2017-10-14 18:13:18.655 ERROR 6417 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No instances available for reservationManagement] with root cause
java.lang.IllegalStateException: No instances available for reservationManagement
CODE:
package project.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import configuration.ReservationConfiguration;
@RestController
@RibbonClient(name = "reservationManagement", configuration = ReservationConfiguration.class)
public class MyController {
@Autowired
private Environment env;
@Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
}
@Autowired
RestTemplate restTemplate;
@RequestMapping(value = "/info")
public String home() {
final String reservationResponse = this.restTemplate.getForObject("http://reservationManagement/info",String.class);
final String flightResponse = env.getProperty("spring.application.name") + " port: " + env.getProperty("server.port");
return flightResponse + " from " + reservationResponse;
}
}
package configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.PingUrl;
import com.netflix.loadbalancer.AvailabilityFilteringRule;
public class ReservationConfiguration {
@Autowired
IClientConfig ribbonClientConfig;
@Bean
/*The default IPing is a NoOpPing (which doesn’t actually ping server instances, instead always reporting that they’re stable), */
public IPing ribbonPing(IClientConfig config) {
return new PingUrl();
}
@Bean
public IRule ribbonRule(IClientConfig config) {
return new AvailabilityFilteringRule();
}
}
application.yml
server:
port: 8080
eureka.client.fetchRegistry: true
reservationManagement:
ribbon:
eureka:
enabled: true
ServerListRefreshInterval: 15000
Eureka服务器位于默认端口上。我错过了什么?
编辑:尤里卡看到这项服务:
答案 0 :(得分:0)
确保您的应用程序预订管理已在Eureka注册表中注册。还可以使用https://reservationManagement/info
答案 1 :(得分:0)
当添加上述依赖时它起作用:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-eureka</artifactId>
<version>2.2.5</version>
</dependency>