Java 如何使用Netflix/Eureka执行故障切换?
我使用Eureka作为我的服务发现和负载平衡器,当有两个服务实例“a”时,它可以正常工作,但是当我停止其中一个实例时,Eureka无法识别其中一个实例已关闭,每次负载平衡器尝试使用死实例时,它都会让我显示一个错误页面 我已将Java 如何使用Netflix/Eureka执行故障切换?,java,spring-boot,spring-cloud,failover,netflix-eureka,Java,Spring Boot,Spring Cloud,Failover,Netflix Eureka,我使用Eureka作为我的服务发现和负载平衡器,当有两个服务实例“a”时,它可以正常工作,但是当我停止其中一个实例时,Eureka无法识别其中一个实例已关闭,每次负载平衡器尝试使用死实例时,它都会让我显示一个错误页面 我已将enableSelfPreservation设置为false,以防止出现这种情况,但Eureka最多需要3-5分钟才能注销该服务,但我希望我的服务具有高可用性,我希望在几秒钟内立即执行故障切换。这是否可能使用Eureka,如果不可能,我如何实现在其他实例已死亡时仅使用活动实例
enableSelfPreservation
设置为false
,以防止出现这种情况,但Eureka最多需要3-5分钟才能注销该服务,但我希望我的服务具有高可用性,我希望在几秒钟内立即执行故障切换。这是否可能使用Eureka,如果不可能,我如何实现在其他实例已死亡时仅使用活动实例
我使用的是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隔离级别设置为线程,并设置超时 注意:这种配置应该在客户端(通常是指网关服务器),因为Ribbon(和SpringCloud)是客户端负载平衡的一种形式 下面是我使用的一个示例:
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