2

Discover Client Properties

spring.application.name=load-balancer-client
spring.cloud.loadbalancer.ribbon.enabled=false
eureka.instance.prefer-ip-address=true
server.port=8081
spring.cloud.loadbalancer.health-check.refetch-instances=true
spring.cloud.loadbalancer.health-check.refetch-instances-interval=2s

API App Properties

spring.application.name=service-api
management.endpoints.web.exposure.include=*
eureka.instance.prefer-ip-address=true
eureka.client.healthcheck.enabled=true

My Client Load Balancer Configuration Looks like this

public class LoadBalancerConfiguration {

    @Bean
    public ServiceInstanceListSupplier instanceSupplier(ConfigurableApplicationContext context) {
        return ServiceInstanceListSupplier.builder()
                .withDiscoveryClient()
                .withHealthChecks()
                .build(context);
    }
}

This is my Configuration class

@Configuration
@LoadBalancerClients(defaultConfiguration = LoadBalancerConfiguration.class)
public class WebClientConfiguration {

    @Bean
    @LoadBalanced
    public WebClient.Builder builder() {
        return WebClient.builder();
    }


    @Bean
    WebClient webClient(WebClient.Builder builder) {
        return builder.build();
    }
}

When I start My Load balancer Client, the rest call fails with the below Error

2021-10-12 11:50:48.962  WARN 21664 --- [        Timer-0] o.s.c.l.core.RoundRobinLoadBalancer      : No servers available for service: service-api
2021-10-12 11:50:48.962  WARN 21664 --- [        Timer-0] eactorLoadBalancerExchangeFilterFunction : LoadBalancer does not contain an instance for the service service-api
2021-10-12 11:50:48.963 ERROR 21664 --- [        Timer-0] reactor.core.publisher.Operators         : Operator called default onErrorDropped

I alternatively tried by enabling health check by using only using only below spring.cloud.loadbalancer.configurations=health-check and it results in Same Error

This happens only when the health check is enabled an it works fine .withHealthChecks() Uncommented

There is no @Configuration Annotation on the custom config class and I have started the registry server, api server and load balancing client in the right order as well Can someone please let me know what the problem is?

  • Finally worked With this Change, we need to pass the rest template to check the health ```@Bean public ServiceInstanceListSupplier serviceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder() .withHints() .withBlockingDiscoveryClient() .withBlockingHealthChecks(new RestTemplate()) .build(context); }``` – Nikhilesh Y Oct 12 '21 at 22:17
  • My experience is that this error occurs because the health check fails - if you debug the code of withBlockingHealthChecks() you will see the check fail and the above error logged. It would really useful if the failed health check was logged too but it isn't. – Paul Keogh Aug 31 '22 at 19:51

0 Answers0