简体   繁体   English

负载均衡器没有可供客户端使用的服务器:会议

[英]Load balancer does not have available server for client: meeting

While I am trying to reach the service meeting via Zuul gateway, Zuul is unable to forward the request to the respective service.当我尝试通过 Zuul 网关到达服务meeting ,Zuul 无法将请求转发到相应的服务。 The following errors are what I am facing:以下错误是我面临的:

  1. nettflix.zuul.exception.ZuulException: Forwarding error nettflix.zuul.exception.ZuulException:转发错误
  2. Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: meeting引起:com.netflix.client.ClientException:负载均衡器没有客户端可用的服务器:会议

Let me share the application.yml for the service, eureka and zuul gateway.让我分享一下服务、eureka 和 zuul 网关的 application.yml。

EurekaClient: Application.yml EurekaClient: Application.yml

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
    lease-renewal-interval-in-seconds: 300
  client:
    register-with-eureka: false
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

ZuulGateWay: application.yml ZuulGateWay: application.yml

server:
  port: 8085

spring:
  application:
    name: gatekeeper


zuul:
  routes:
    meeting: /meeting/**
    serviceId: meeting

ribbon:
  eureka:
    enabled: false

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

ZuulGateWay: SpringBootApplication ZuulGateWay: SpringBootApplication

package com.sagarp.gatekeeper;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
public class MeetingApplication {

    public static void main(String[] args) {
        SpringApplication.run(MeetingApplication.class, args);
    }
}

My Service class (meeting): Application.yml我的服务类(会议): Application.yml

server:
  port: 0
spring:
  application:
    name: meeting
  datasource:
    url: jdbc:mysql://localhost:3306/sagarp?useSSL=false
    username: myUserName
    password: myPassWord
  jpa:
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    hibernate:
     ddl-auto: update

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    lease-renewal-interval-in-seconds: 5

My Service class (meeting): SpringBootApplication我的服务类(会议): SpringBootApplication

package com.sagarp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class MeetingApplication {

    public static void main(String[] args) {
        SpringApplication.run(MeetingApplication.class, args);
    }
}

As you can see, the configuration ensures that all my services are discovered by eureka client.如您所见,该配置可确保 eureka 客户端发现我的所有服务。

In the eureka console, I have verified the same, the zuul gateway and my service(meeting) both are visible.在尤里卡控制台中,我已经验证过, zuul gatewaymy service(meeting)都是可见的。

For better view, you can visit my git repo.为了更好地查看,您可以访问我的 git repo。 https://github.com/sagar-patro/demo-microservices https://github.com/sagar-patro/demo-microservices

Any help would be very much appreciable任何帮助将是非常可观的

Short answer简答

ribbon:
  eureka:
    enabled: false

Spring Cloud Netflix Zuul uses Netflix's Ribbon to perform client-side load balancing , and by default, Ribbon would use Netflix Eureka for service discovery . Spring Cloud Netflix Zuul使用Netflix 的 Ribbon进行客户端负载均衡,默认情况下, Ribbon会使用Netflix Eureka进行服务发现 You are skipping service discovery , so you've set ribbon.eureka.enabled to false .您正在跳过服务发现,因此您已将ribbon.eureka.enabled设置为false Since Ribbon now can't use Eureka to look up services, you must specify an url for the meeting service:由于Ribbon现在无法使用Eureka查找服务,因此您必须为meeting服务指定一个 url:

meeting:
  ribbon:
    listOfServers: localhost:8080

Expanded answer扩展答案

I will make it more clear for you.我会为你说得更清楚。

The dependency org.springframework.cloud:spring-cloud-starter-netflix-zuul , which you are currently using in the gatekeeper project, has several compile dependencies:您当前在gatekeeper项目中使用的依赖项org.springframework.cloud:spring-cloud-starter-netflix-zuul有几个编译依赖项:

com.netflix.zuul:zuul-core
org.springframework.boot:spring-boot-starter-web        
org.springframework.boot:spring-boot-starter-actuator       
org.springframework.cloud:spring-cloud-netflix-zuul
org.springframework.cloud:spring-cloud-starter      
org.springframework.cloud:pring-cloud-starter-netflix-hystrix
org.springframework.cloud:spring-cloud-starter-netflix-ribbon
org.springframework.cloud:spring-cloud-starter-netflix-archaius

As you see, it constitutes many components gathered around the com.netflix.zuul:zuul-core module (including Eureka for instance discovery and Ribbon for routing):如您所见,它由围绕com.netflix.zuul:zuul-core模块(包括 Eureka 实例发现和 Ribbon 路由)聚集的许多组件组成:

在此处输入图片说明

When you are launching the gatekeeper application, the default ZuulProxyAutoConfiguration configuration is being applied.当您启动gatekeeper应用程序时,将应用默认的ZuulProxyAutoConfiguration配置。 It imports Ribbon configuration classes:它导入功能区配置类:

@Configuration
@Import({ RibbonCommandFactoryConfiguration.RestClientRibbonConfiguration.class,
        RibbonCommandFactoryConfiguration.OkHttpRibbonConfiguration.class,
        RibbonCommandFactoryConfiguration.HttpClientRibbonConfiguration.class,
        HttpClientConfiguration.class })
@ConditionalOnBean(ZuulProxyMarkerConfiguration.Marker.class)
public class ZuulProxyAutoConfiguration extends ZuulServerAutoConfiguration { ... }

HttpClientRibbonConfiguration , in turn, initialises RibbonLoadBalancingHttpClient which is responsible for the error messages you saw. HttpClientRibbonConfiguration依次初始化RibbonLoadBalancingHttpClient ,它负责您看到的错误消息。

That RibbonLoadBalancingHttpClient by default utilises ZoneAwareLoadBalancer which comes from a com.netflix.ribbon:ribbon-loadbalancer package:也就是说RibbonLoadBalancingHttpClient默认利用ZoneAwareLoadBalancer它来自一个com.netflix.ribbon:ribbon-loadbalancer包:

By default Zuul load balances using the ZoneAwareLoadBalancer from Ribbon.默认情况下,Zuul 使用 Ribbon 中的ZoneAwareLoadBalancer负载平衡。 The algorithm is a round robin of the instances available in discovery, with availability zone success tracking for resiliency.该算法是发现中可用实例的循环,具有可用性区域成功跟踪以实现弹性。 The load balancer will keep stats for each zone and will drop a zone if the failure rates are above a configurable threshold.负载均衡器将保留每个区域的统计信息,如果故障率高于可配置的阈值,则将删除一个区域。

If you want to use your own custom load balancer you can set the NFLoadBalancerClassName property for that Ribbon client namespace or override the getLoadBalancerClass() method in the DefaultClientChannelManager .如果您想使用自己的自定义负载均衡器,您可以为该 Ribbon 客户端命名空间设置NFLoadBalancerClassName属性或覆盖DefaultClientChannelManagergetLoadBalancerClass()方法。 Note that your class should extend DynamicServerListLoadBalancer .请注意,您的类应该扩展DynamicServerListLoadBalancer

It explains that Zuul delegates routing and load balancing work to Ribbon components and proves that you are actually using Ribbon in the gatekeeper project.它解释了 Zuul 将路由和负载平衡工作委托给 Ribbon 组件,并证明您实际上在gatekeeper项目中使用了 Ribbon。

Unless you choose a different load balancer, you should go for my original answer.除非您选择不同的负载均衡器,否则您应该选择我的原始答案。
I hope it will help.我希望它会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Feign、SSL 和 Load Balancer 创建 Spring 客户端 - Creating Spring client with Feign, SSL and Load Balancer .Net是否为客户端和服务器提供了不同的环境? - Does .Net have a different environment for client and server? 在F5负载均衡器跟踪会话的情况下,如何从同一Web服务器处理一个客户端的所有请求? - How to server all request of one client from the same web server in case of f5 load balancer to track session? 在IBM Websphere环境中设置负载平衡器服务器 - settingup load balancer server in IBM Websphere environment 负载均衡器环境中的java服务器端缓存 - java server side Caching on load balancer enviroment 基于 pod 上可用连接数的 Kubernetes 上的自定义负载均衡器 - Custom Load Balancer on Kubernetes based on number of available connections on the pod Java客户端通过F5 BIG-IP负载平衡器与IIS服务器进行SSL握手时收到“连接重置” - Java client receives “connection reset” during SSL handshake with IIS server via F5 BIG-IP load balancer Spring 引导 HTTP 不带负载均衡器的多台服务器的客户端 - Spring Boot HTTP Client of multiple servers WITHOUT load balancer 使用 Spring 云负载均衡器时出现错误“FeignException$ServiceUnavailable: Load balancer does not contain an instance for the service ...” - Error “FeignException$ServiceUnavailable: Load balancer does not contain an instance for the service …” while using Spring Cloud Load Balancer 我的Netty客户端如何检测我的Netty服务器是否侦听端口(可用)? - How can I have my netty client detect if my netty server listens on a port (is available)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM