简体   繁体   English

Service Fabric Unhandled Exceptions和最佳实践

[英]Service Fabric Unhandled Exceptions and best practices

Just curious if anyone has experience with unhandled exceptions in Service Fabric and what the best practices surrounding them are. 只是好奇是否有人对Service Fabric中未处理的异常有经验以及围绕它们的最佳实践。 Mainly curious about faulted state of services. 主要是对服务的故障状态感到好奇。 Do the services get recycled if they are in a faulted state? 如果服务处于故障状态,服务是否会被回收? Or should there be global exception handling for unhandled exceptions, if that concept even exists in SF. 或者是否应该对未处理的异常进行全局异常处理,如果该概念甚至存在于SF中。 I haven't found much on this topic doing searches. 我在搜索这个主题上找不到太多东西。

At my company we've built some re-usable code following the guidelines for using ITransaction , that allows us to run any arbitrary code and have it wrapped up with the appropriate exception handling and retry policies. 在我的公司,我们按照使用ITransaction指导原则构建了一些可重用的代码,这使得我们可以运行任意代码并使用适当的异常处理和重试策略进行包装。 Within that documentation, there is guidance on how the various types of exceptions should affect the RunAsync method, as well as how they should affect methods that are part of a remoting endpoint. 在该文档中,有关于各种类型的异常应如何影响RunAsync方法的指导,以及它们应如何影响作为远程终结点的一部分的方法。

Generally, the handling of any exceptions outside of what is discussed in the documentation, is up to you to decide. 通常,处理文档中讨论的任何异常都取决于您自己决定。 For myself, I will simply let the exception bubble up and let the service fail if its an unexpected exception. 对于我自己,我只是让异常冒出来,如果出现意外异常,请让服务失败。 Expected exceptions should always be handled with an appropriate retry policy. 应始终使用适当的重试策略处理预期的异常。

Your question is quite broad, and the answer changes depending on the type of micro-service. 您的问题非常广泛,答案会根据微服务的类型而变化。 Once good point to start, also getting an idea of the vastitude of this subject, is to look at the Service Fabric health monitoring article and related subtopics. 一旦获得好点,也要了解这个主题的大部分内容,就是查看Service Fabric健康监控文章和相关的子主题。 As you can see there are plenty of configuration choices, and in my experience (I'm a Microsoft Azure Architect) there is no silver bullet, no "one size fits all" solution. 正如您所看到的,有很多配置选择,根据我的经验(我是Microsoft Azure架构师),没有银弹,没有“一刀切”的解决方案。 The only best practice is to design the exception management that serves the best to your project, leveraging the Fabric health policies as much as possible. 唯一的最佳做法是设计最适合您项目的异常管理,尽可能地利用Fabric健康策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM