Unable to Enable Health Check in Spring Cloud Gateway Client
Spring Cloud Version : 2020.0.4 Spring Boot version : 2.5.5
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
Code For calling API
ConfiguredWebClientRunner(WebClient http) {
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
call(http, "http://service-api/hello").subscribe(greeting -> System.out.println("configured: " + greeting));
}
}, 0, 2000);
}
static Flux<String> call(WebClient http, String url) {
return http.get().uri(url).retrieve().bodyToFlux(String.class);
}
}
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?
Stack Overflow Link :https://stackoverflow.com/questions/69545879/enable-health-checks-in-spring-cloud-load-balancer-will-not-work-when-using-cust
this is related to https://giters.com/spring-cloud/spring-cloud-commons/issues/978?amp=1
Hello @nyacham , the 2020.0.x release train has not been supported for some time now. Please verify against a supported version, such as Spring Cloud 2021.0.3 and let us know if the issue persists.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.