Load balancer does not have available server for client: meeting

后端 未结 1 921
误落风尘
误落风尘 2021-02-02 17:29

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

相关标签:
1条回答
  • 2021-02-02 17:56

    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. 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.

    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
    

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

    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, in turn, initialises RibbonLoadBalancingHttpClient which is responsible for the error messages you saw.

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

    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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题