[英]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:以下错误是我面临的:
- nettflix.zuul.exception.ZuulException: Forwarding error
nettflix.zuul.exception.ZuulException:转发错误
- 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 gateway
和my 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任何帮助将是非常可观的
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
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 thegetLoadBalancerClass()
method in theDefaultClientChannelManager
.如果您想使用自己的自定义负载均衡器,您可以为该 Ribbon 客户端命名空间设置
NFLoadBalancerClassName
属性或覆盖DefaultClientChannelManager
的getLoadBalancerClass()
方法。 Note that your class should extendDynamicServerListLoadBalancer
.请注意,您的类应该扩展
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.