使用 Feign、Ribbon 和 Eureka 管理容错

Manage Fault Tolerance with Feign, Ribbon and Eureka

我想使用 Feign Client、Ribbon 和 Eureka 实现弹性微服务架构,所以我遇到了一个问题。当微服务目标关闭时,我想重定向到另一个微服务实例而不让用户看到它。例如,我有 4 个微服务实例 B 和一个实例 A :

浏览器客户端调用 A,然后 A 调用 B1,但 B1 已关闭 => A 自动重定向到 B2,B2 被 KO,然后 A 调用 B3,B3 启动,然后它 returns 对 A 的响应。 returns 响应浏览器客户端。

请问我该如何实现。 提前致谢。

基本上,Ribbon 应该已经为您找到了存活的实例 - 首先,Eureka 存储和更新关于哪些实例存活的信息,其次,Ribbon 运行 health-check requests to the instances. If that is not working correctly for you, you can try customising the polling intervals for Ribbon. If you want a failed request to be repeated against a different instance, you can use Spring Cloud Netflix Ribbon with Spring Retry (see documentation)。

话虽如此,由于 Spring Cloud Ribbon is now in maintenance mode and will not be making it into the 2020.0.0 release train, I would definitely not encourage adding it at this point. The available alternative is Spring Cloud LoadBalancer. It supports retrieving the instances that are alive from Service Discovery (either with or without caching and health-checks. It does not support retries at this point, but there's an issue 在项目积压中。