发现客户端属性
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 应用程序属性
spring.application.name=service-api
management.endpoints.web.exposure.include=*
eureka.instance.prefer-ip-address=true
eureka.client.healthcheck.enabled=true
我的客户端负载均衡器配置如下所示
public class LoadBalancerConfiguration {
@Bean
public ServiceInstanceListSupplier instanceSupplier(ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder()
.withDiscoveryClient()
.withHealthChecks()
.build(context);
}
}
这是我的配置类
@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();
}
}
当我启动我的负载均衡器客户端时,其余调用失败并出现以下错误
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
我或者尝试通过仅使用以下仅使用启用运行状况检查
spring.cloud.loadbalancer.configurations=health-check
并导致相同的错误
仅当启用了运行状况检查并且工作正常时才会发生这种.withHealthChecks()
情况
自定义配置类上没有@Configuration
注释,我也以正确的顺序启动了注册表服务器、api服务器和负载平衡客户端有人可以告诉我问题是什么吗?