Service Fabric-如何正常关闭应用程序 [英] Service Fabric - how to gracefully fail an app
问题描述
我在应用程序中有一组无状态和有状态服务.显然,我希望它们能够完美运行,但是在某些情况下,我的应用程序知道它无法从故障中恢复.例如,如果它无法从KeyVault(及其故障转移副本)加载其配置设置,则毫无意义.
I have a set of stateless and stateful services in an app. Obviously I'd like them to run perfectly but there are instances where my app knows it cannot recover from a failure. For example, if it cannot load its configuration settings from KeyVault (and its failover copies), then there is no point going any further.
问题是,如何告诉服务架构放弃整个应用程序?我试过Partition.ReportFault(FaultType.Permenant),但保佑它,它尝试启动一个新分区. :-)
So question is, how to tell service fabric to give up the whole app? I have tried Partition.ReportFault(FaultType.Permenant) but bless it, it tries to start a new partition. :-)
很显然,我们将警报信息发送到Ops和DevOps包括自动电子邮件,以便它们可以恢复,但是如果Service Fabric可以接受自杀"请求而不是生成(重复计数x重试计数)致命错误报告数并最终死亡,则很好.
Obviously we are sending alerts info to Ops and DevOps incl automated emails so they can recover but great if Service Fabric can accept a "suicide" request rather than generating (replica count x retry count) number of fatal error reports and eventually dying.
推荐答案
您想要的是 删除 服务.这是一个简单的管理操作,任何具有对群集的管理员访问权限即可.如果您想自杀,服务可以通过这种方式删除自己:
What you want is to delete the service. That's a simple management operation that anyone with admin access to the cluster can do. A service can delete itself this way if you want it to commit suicide:
using (FabricClient fc = new FabricClient())
{
fc.ServiceManager.DeleteServiceAsync(this.Context.ServiceName);
}
请注意,这要求服务具有对集群管理操作的管理员访问权限.如果该服务具有面向Internet的终结点,则可能不希望这样做(如果有人设法利用您服务中的漏洞并控制了流程,那么您就会被水管).在这种情况下,最好将删除任务委派给另一个服务-执行者(如果您愿意)-该执行者具有管理员权限,只能从群集内部进行访问,并且无论如何都可以删除死在水中的服务.
Note that this requires the service to have admin access to cluster management operations. You might not want that if the service has Internet-facing endpoints (if someone manages to take advantage of a vulnerability in your service and take control of the process, you're hosed). In that case, it would be better to delegate the delete task to another service - an executioner, if you will - that has admin access, is only accessible from inside the cluster, and can delete services that are dead in the water anyway.
这篇关于Service Fabric-如何正常关闭应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!