Polly Circuit breaker pattern - For testing connection strings

前端 未结 1 1079
轮回少年
轮回少年 2020-12-22 02:20

I\'m trying to test whether the connection string is null using Polly. If it is null, I want to try three times using the CircuitBreaker and the message should be outputted

相关标签:
1条回答
  • 2020-12-22 03:03

    I believe you have misunderstood what the CircuitBreaker policy does, as described at this similar question: Polly framework CircuitBreakerAsync does not retry if exception occur

    A circuit-breaker does not of itself orchestrate any retries. Rather, it exists to measure the rate of faults on delegates executed through it - and trip the circuit if the fault rate becomes too high. As its purpose is only as a measuring-and-breaking device, it indeed rethrows exceptions from delegates executed through it: hence the NullReferenceException you are seeing rethrown.

    EDIT: This behaviour of the circuit-breaker, and its difference from retry, is also clearly described in the Polly wiki, at: https://github.com/App-vNext/Polly/wiki/Circuit-Breaker

    To do what I think you want to do, you need to combine retry policy with circuit breaker policy as described at Polly framework CircuitBreakerAsync does not retry if exception occur. Polly now offers PolicyWrap to make combining policies easy.

    0 讨论(0)
提交回复
热议问题