负载平衡器没有可供客户端使用的服务器:会议 [英] Load balancer does not have available server for client: meeting

查看:631
本文介绍了负载平衡器没有可供客户端使用的服务器:会议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图通过Zuul网关访问服务meeting时,Zuul无法将请求转发到相应的服务.我面临以下错误:

While I am trying to reach the service meeting via Zuul gateway, Zuul is unable to forward the request to the respective service. The following errors are what I am facing:

  1. nettflix.zuul.exception.ZuulException:转发错误
  2. 原因:com.netflix.client.ClientException:负载均衡器没有可用的服务器用于客户端:会议

让我共享用于服务,尤里卡和zuul网关的application.yml.

Let me share the application.yml for the service, eureka and zuul gateway.

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

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

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

我的服务班级(会议): 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

我的服务班级(会议): 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);
    }
}

如您所见,该配置确保eureka客户端发现了我的所有服务.

As you can see, the configuration ensures that all my services are discovered by eureka client.

在eureka控制台中,我已经验证了相同的内容,zuul gatewaymy service(meeting)都可见.

In the eureka console, I have verified the same, the zuul gateway and my service(meeting) both are visible.

为获得更好的视图,您可以访问我的git repo. https://github.com/sagar-patro/demo-microservices

For better view, you can visit my git repo. https://github.com/sagar-patro/demo-microservices

任何帮助都是非常有意义的

Any help would be very much appreciable

推荐答案

简短答案

ribbon:
  eureka:
    enabled: false

Spring Cloud Netflix Zuul 使用 Netflix的Ribbon 来执行客户端负载平衡,默认情况下是 Ribbon >会使用 Netflix Eureka 进行服务发现.您正在跳过服务发现,因此已将ribbon.eureka.enabled设置为false.由于丝带现在无法使用 Eureka 查找服务,因此必须为meeting服务指定一个URL:

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. You are skipping service discovery, so you've set ribbon.eureka.enabled to false. Since Ribbon now can’t use Eureka to look up services, you must specify an url for the meeting service:

meeting:
  ribbon:
    listOfServers: localhost:8080

扩展答案

我将为您澄清一下.

Expanded answer

I will make it more clear for you.

依赖项 org.springframework.cloud:spring-cloud-starter-netflix-zuul ,您当前在gatekeeper项目中使用的代码具有几个编译依赖项:

The dependency org.springframework.cloud:spring-cloud-starter-netflix-zuul, which you are currently using in the gatekeeper project, has several compile dependencies:

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

如您所见,它由 com.netflix.zuul:zuul-core 模块(包括用于实例发现的Eureka和用于路由的Ribbon):

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):

启动gatekeeper应用程序时,将应用默认的ZuulProxyAutoConfiguration配置.它导入功能区配置类:

When you are launching the gatekeeper application, the default ZuulProxyAutoConfiguration configuration is being applied. 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依次初始化RibbonLoadBalancingHttpClient,它负责您看到的错误消息.

HttpClientRibbonConfiguration, in turn, initialises RibbonLoadBalancingHttpClient which is responsible for the error messages you saw.

默认情况下,RibbonLoadBalancingHttpClient使用来自com.netflix.ribbon:ribbon-loadbalancer软件包的ZoneAwareLoadBalancer:

That RibbonLoadBalancingHttpClient by default utilises ZoneAwareLoadBalancer which comes from a com.netflix.ribbon:ribbon-loadbalancer package:

默认情况下,使用Ribbon上的ZoneAwareLoadBalancer进行Zuul负载均衡.该算法是发现中可用实例的循环轮询,并跟踪可用性区域成功性以实现弹性.负载均衡器将保留每个区域的统计信息,如果故障率高于可配置的阈值,则该负载均衡器将删除该区域.

By default Zuul load balances using the ZoneAwareLoadBalancer from Ribbon. 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.

如果要使用自己的自定义负载平衡器,则可以为该Ribbon客户端名称空间设置NFLoadBalancerClassName属性,或覆盖DefaultClientChannelManager中的getLoadBalancerClass()方法.请注意,您的班级应扩展DynamicServerListLoadBalancer.

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. Note that your class should extend DynamicServerListLoadBalancer.

它说明Zuul将路由和负载平衡工作委托给Ribbon组件,并证明您实际上在gatekeeper项目中使用了Ribbon.

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.

除非您选择其他负载均衡器,否则应选择我的原始答案.
希望对您有所帮助.

Unless you choose a different load balancer, you should go for my original answer.
I hope it will help.

这篇关于负载平衡器没有可供客户端使用的服务器:会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆