Exemplo n.º 1
0
 public static RetryPolicy <HttpResponseMessage> GetHttpRetryPolicy(ILogger logger, IRetryPolicyConfig retryPolicyConfig)
 {
     return(HttpPolicyBuilders.GetDefaultBuilder()
            .WaitAndRetryAsync(retryPolicyConfig.RetryCount,
                               ComputeDuration,
                               (result, timeSpan, retryCount, context) =>
     {
         OnHttpRetry(result, timeSpan, retryCount, context, logger);
     }));
 }
 public static CircuitBreakerPolicy <HttpResponseMessage> GetHttpCircuitBreakerPolicy(ILogger logger, ICircuitBreakerPolicyConfig circuitBreakerPolicyConfig)
 {
     return(HttpPolicyBuilders.GetDefaultBuilder()
            .CircuitBreakerAsync(circuitBreakerPolicyConfig.RetryCount + 1,
                                 TimeSpan.FromSeconds(circuitBreakerPolicyConfig.BreakDuration),
                                 (result, breakDuration) =>
     {
         OnHttpBreak(result, breakDuration, circuitBreakerPolicyConfig.RetryCount, logger);
     },
                                 () =>
     {
         OnHttpReset(logger);
     }));
 }