2017-10-14 94 views
1

我用Ribbon和Netflix Eureka創建了一個簡單的項目。尤里卡工作正常,我可以看到所有註冊的服務。但是,功能區負載平衡器不會看到這些服務。實際上,在它打印的日誌中,它會在「當前服務器列表」中看到服務器,但是我得到的例外情況是找不到任何實例。我將是一些提示,萬分感謝,我花了很多時間(和天)弄明白.... 日誌: (我代替我的IP)Ribbon和Eureka - 沒有實例

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.springf[email protected]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 

尤里卡服務器是默認的端口上。 我錯過了什麼?

編輯: 尤里卡看到這個服務: screen

回答

0

確保你的應用reservationManagement註冊尤里卡註冊表。也可以使用https://reservationManagement/info

+0

是的,我更新了Eureka頁面的屏幕。爲何選擇https? –

+0

HTTPS也無法正常工作 –

+0

有關這方面的任何消息嗎? – seven