我使用 Eureka 作为我的服务发现和负载均衡器,当有两个服务“A”实例时它工作正常,但是当我停止其中一个实例时,Eureka 无法识别其中一个实例已关闭,每次负载均衡器尝试使用失效实例时,它都会显示错误页面。
我已将 enableSelfPreservation
设置为 false
以防止出现这种情况,但 Eureka 最多需要 3 - 5 分钟才能取消注册该服务,但我希望我的服务具有高可用性我想在几秒钟内立即执行故障转移。使用 Eureka 是否可以实现这一点,如果不是,我如何才能在其他实例死亡时仅使用 Activity 实例。
我使用的是 Spring Boot,这是我的 Eureka 服务器配置。
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
enableSelfPreservation: false
最佳答案
您应该将功能区配置添加到您的 application.yml 中。还建议将 hystrix 隔离级别设置为 THREAD,并设置超时。
注意:此配置应该位于客户端(这通常意味着您的网关服务器),因为 Ribbon(以及一般的 Spring Cloud)是客户端负载平衡的一种形式。
这是我使用的一个示例:
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 40000 #Timeout after this time in milliseconds
ribbon:
ConnectTimeout: 5000 #try to connect to the endpoint for 5 seconds.
ReadTimeout: 5000 #try to get a response after successfull connection for 5 seconds
# Max number of retries on the same server (excluding the first try)
maxAutoRetries: 1
# Max number of next servers to retry (excluding the first server)
MaxAutoRetriesNextServer: 2
关于java - 如何使用 Netflix/Eureka 执行故障转移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37901994/