当前位置: 首页 > 知识库问答 >
问题:

Ribbon和Eureka-没有可用的实例

贡和裕
2023-03-14

我用Ribbon和Netflix Eureka创建了一个简单的项目。尤里卡运作良好,我可以看到所有注册服务。但是,Ribbon负载平衡器看不到这些服务。实际上,在它打印的日志中,它在“当前服务器列表”中看到了服务器,但是我得到一个例外,没有找到任何实例。如果能给我一些提示,我将不胜感激,我花了很多时间(甚至几天)才弄明白。

日志(我用

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

代码:

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();
  }

}

应用yml

server:
  port: 8080
eureka.client.fetchRegistry: true
reservationManagement:
  ribbon:
    eureka:
      enabled: true
    ServerListRefreshInterval: 15000

Eureka服务器位于默认端口上。我错过了什么?

编辑:尤里卡看到这个服务:


共有2个答案

李永寿
2023-03-14

它的工作原理时添加上面的依赖:

<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>
翟卓君
2023-03-14

确保您的应用程序reservationManagement已在Eureka注册表中注册。也使用https://reservationManagement/info

 类似资料:
  • 我正在使用带有 netflix 堆栈和 Spring 启动的微服务构建一个应用程序。困扰我的一件事是,我还没有集成测试,我可以在其中模拟周围的服务。 因此,我有一个服务 A,它是一个带有功能区的尤里卡客户端,用于在呼叫期间将尤里卡名称解析为已注册服务 B 的 URL。 所以理想情况下,我想用 spring boot 的 integrationtest 注释启动应用程序,使用 wiremock 模拟

  • 我想使用Feign Client、Ribbon和Eureka实现一个弹性的微服务架构,所以我遇到了一个问题。当一个微服务目标关闭时,我希望重定向到另一个微服务实例,而不让用户看到它。例如,我有4个微服务B实例和一个实例A:

  • 我正在使用Spring Cloud和Netflix OSS Eureka和Ribbon开发微服务。我有另一个服务作为oauth-server运行,它提供OAuth2令牌。我的所有微服务都向Eureka注册,包括oauth-server。如果我使用oauth-server的硬编码url作为“clientCredentialsResourceDetails.setAccessTokenUri(”htt

  • introduction 在上一篇中阐述了ribbon的基本用法,但是可以发现服务列表是通过配置得来的,实际 情况通常是由负载均衡+服务发现来实现的,通过服务发现获取服务列表,负载均衡通过rule选择要调用的服务。服务发现可以通过eureka来实现,后期会讲解利用consul做服务发现。 eureka discovery service eureka服务发现在前面的文章中已经提供到,这里直接给出代

  • 我们有一个架构体系,有自己的应用编程接口网关、服务发现和负载平衡。然而,出于恢复目的,我需要使用Hystrix。 与Spring的云Netflix,可以Hystrix(即。断路器注释)在没有Eureka/Ribbon或其他NetflixOSS模块的情况下使用? 是否有任何依赖于Eureka/Ribbon/Zuul的断路器仪表板(即涡轮机和流聚合器)? 断路器注释可以在非Spring启动应用程序中使

  • 是否有一种方法可以调用支持Eureka的服务,而无需调用消费者向Eureka注册?或者换句话说,没有@EnableEurekClient注释?或者换言之,是否有一种方法可以从非Spring Java应用程序中使用带状负载平衡器调用支持Eureka的服务? 我无法从文档中得到它。有这样的例子吗?