本文介绍了使 Spring Cloud 应用程序在完全关闭之前等待 eureka 客户端将其删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序接收来自其他服务的调用,这些服务使用 Eureka 来发现不同应用程序实例/副本的不同 IP 地址.

We have an application that's receiving calls from other services that use Eureka to discover the different IP addresses of the different application instances/replicas.

在部署此应用程序的新版本时,我们的部署系统(在我们的示例中为 kubernetes)会向应用程序实例之一发送 SIGTERM 以将其关闭.

When deploying a new version of this app, our deployment system (kubernetes in our case) sends a SIGTERM to one of the instances of the application to shut it down.

但是服务中的 Eureka 客户端向应用程序发送请求,保留了 Eureka 信息的本地缓存.这意味着这些应用程序不会意识到应用程序的实例已关闭,它们会继续向不再工作的实例发送请求.

But the Eureka client in the services sending requests to the application, keeps a local cache of Eureka's information. Meaning that these applications won't realize that the instance of the app has been shutt down, and they will continue to send requests to an instance that is no longer working.

有没有办法让 Spring Cloud 应用程序在关闭之前等待几秒钟,以确保所有客户端都有更新的 Eureka 信息(此应用程序将不再列出)?

Is there a way to make a Spring Cloud application to wait for some seconds before shutting down to make sure that all clients have the updated Eureka information (where this app won't be listed anymore)?

推荐答案

如果您使用的是 Kubernetes,那么您可以将 Service 映射到在 eureka 注册的每个应用程序/服务,并告诉应用程序使用服务名称进行注册而不是IP.然后,您可以使用 Kubernetes 管理蓝/绿部署(前提是您已设置探针).然后 Eureka 将只知道服务名称以及是否为它们注册了某些东西,Kubernetes 将在升级期间管理可用性.这有点像混合模型.

If you're using Kubernetes then you could map a Service to each of the apps/services that register with eureka and tell the apps to register using the service name instead of an IP. Then you can manage the blue/green deploy with Kubernetes (provided you've got probes set up). Eureka will then just know about the Service names and whether something is registered for them and Kubernetes will be managing availability during the upgrade. It's a bit of a hybrid model.

如果您要删除应用程序或更改名称而不是升级,那么我认为您需要为 eureka 注册数据设置租用时间.Eureka 从不注销服务

If you are removing an app or changing the name rather than upgrading then I think you'll need to set a lease time for the eureka registration data. Eureka never unregisters a service

这篇关于使 Spring Cloud 应用程序在完全关闭之前等待 eureka 客户端将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 12:23