【发布时间】:2018-04-09 22:25:24
【问题描述】:
我已经使用 Spring Boot、Eureka、Zuul、Ribbon 框架配置了我的项目架构。 它工作正常,但有时(很少)会出现以下异常:
- 原因:com.netflix.client.ClientException:负载均衡器没有可用于客户端的服务器:service1
- 原因:com.netflix.hystrix.exception.HystrixRuntimeException:service1 超时且没有可用的回退。
以下是我的服务配置: 看看,如果我遗漏了导致上述异常问题的任何内容,请告诉我。
eureka 服务应用程序.properties:
server.port=8070
spring.application.name=eureka_service
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:8070/eureka/
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
zuul 服务应用程序.properties:
server.port=8071
spring.application.name=zuul_service
zuul.prefix=/api
zuul.routes.service1.path=/service1/**
zuul.routes.service1.service-id=service1
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:8070/eureka/
ribbon.eureka.enabled=true
service1 application.properties:
server.port=8072
spring.application.name=service1
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:8070/eureka/
ribbon.eureka.enabled=true
如果我需要添加任何其他配置来解决,请告诉我? 谢谢。
【问题讨论】:
-
这些异常是否在启动时出现?如果运气不好,可能需要 120 秒才能在服务之间共享元数据以进行发现。此外,Hystrix 有一个默认的 1 秒超时,线程池为 10,如果您保持 Hystrix 的默认设置,您可以轻松地自己执行 DOS。
-
@DarrenForsythe 这些异常不在启动时。当我尝试通过 Zuul 访问 service1 API 时,我得到了。 localhost:8071/api/security1/user***** 如何解决这些异常?
-
我应该澄清一下,在应用程序出现后,您尝试访问 API 的速度有多快?
-
@DarrenForsythe 在所有服务都启动并运行并确保所有服务在 Eureka 服务器上成功注册之后,我尝试访问 API。我得到了这些异常,有时是在服务器启动后 API 第一次命中,有时是在几次命中后。我不明白这是什么问题!!!
标签: spring-boot netflix-eureka netflix-zuul spring-cloud-netflix