Enable Health Checks in Spring Cloud Load balancer will not work when using Custom Config

2.6k Views Asked by At

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?

0

There are 0 best solutions below