简体   繁体   English

捕获所有异常或特定异常的断路器的最佳实践是什么?

[英]What is the best practice for a Circuit Breaker, catch all Exceptions or specific ones?

So I'm using Polly (fantastic) for a circuit breaker in C#. 所以我在C#中使用Polly (很棒)作为断路器。

I was using it to just catch a handful of exceptions when calling a web service, for example: 我使用它只是在调用Web服务时捕获了一些异常,例如:

    _policy = Policy
        .Handle<TargetInvocationException>()
        .Or<CommunicationException>()
        .Or<EndpointNotFoundException>()
...

But I'm wondering if it would be far easier to just do: 但是我想知道这样做是否会容易得多:

   _policy = Policy
        .Handle<Exception>()

Then in the case of the service call having any issues of any kind I am covered. 然后,在服务电话遇到任何类型的问题的情况下,我都将得到承保。 However I'm worried now that by doing this I'll cause myself issues in future that I haven't considered. 但是,现在我担心这样做会导致我将来未曾考虑过的问题。

Any thoughts? 有什么想法吗?

Sorry if I'm a bit late to the party but I just put together a library for just this situation and to allow for the circuit to run over different threads such as requests from a web server: 抱歉,如果我来晚了一点,但是我只是为这种情况建立了一个库,并允许电路在不同的线程上运行,例如来自Web服务器的请求:

https://github.com/InvitationDigital/IDL.Net.CircuitBreaker https://github.com/InvitationDigital/IDL.Net.CircuitBreaker

This allows you to catch your exceptions and only get circuit breaker errors when the circuit is open. 这样,您就可以捕获异常,并且仅在电路断开时才会得到断路器错误。

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

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