即使在我停止注册服务器后,Eureka 客户端仍然可以工作并相互通信。如何?

Eureka client works and communicates with each other even after i stopped the registered server. How?

我已经创建了一个 Eureka 服务器并向其注册了两个客户端。客户之间沟通顺畅

在那之后,我停止了 Eureka 服务器,但我的两个客户端仍然可以顺利地相互通信。这怎么可能?我在第一个客户端中使用以下代码与第二个客户端通信。

ServiceInstance instance = loadbalancerclient.choose(secondService);
URI uri=URI.create(String.format("http://%s:%s"+"/test",instance.getHost(),instance.getPort()));
ResponseEntity<String> result = restTemplate.getForEntity(uri.toString(),String.class);

因为我没有硬编码任何 URL 我在 Eureka 服务器中使用第二个客户端的注册名称,我不希望它在服务器关闭时工作。任何人都可以向我解释为什么会这样吗?

来自尤里卡 documentation:

Fetch Registry

Eureka clients fetches the registry information from the server and caches it locally. After that, the clients use that information to find other services. This information is updated periodically (every 30 seconds) by getting the delta updates between the last fetch cycle and the current one. The delta information is held longer (for about 3 mins) in the server, hence the delta fetches may return the same instances again. The Eureka client automatically handles the duplicate information.

After getting the deltas, Eureka client reconciles the information with the server by comparing the instance counts returned by the server and if the information does not match for some reason, the whole registry information is fetched again. Eureka server caches the compressed payload of the deltas, whole registry and also per application as well as the uncompressed information of the same. The payload also supports both JSON/XML formats. Eureka client gets the information in compressed JSON format using jersey apache client.

Eureka 不处理两个服务器之间的通信,只处理注册。这意味着服务仅使用 Eureka 来查找其他服务的地址。之后直接在两个服务之间进行通信,无需 Eureka。

如果 Eureka 宕机,客户端使用远程服务地址的缓存副本,这有利于弹性和临时网络故障。

稍微想想,为什么不行呢?如果 Eureka 挂了,并不意味着远程服务也挂了或者它的物理地址已经改变了。