Browse Source

Removed unused file

pull/632/head
Unai Zorrilla Castro 6 years ago
parent
commit
fb15ed1e11
4 changed files with 6 additions and 80 deletions
  1. +2
    -2
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs
  2. +2
    -2
      src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs
  3. +0
    -74
      src/Web/WebMVC/Infrastructure/HttpClientDefaultPolicies.cs
  4. +2
    -2
      src/Web/WebMVC/Startup.cs

+ 2
- 2
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs View File

@ -149,11 +149,11 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
//register http services
var retriesWithExponentialBackoff = HttpPolicyExtensions
.HandleTransientHttpError()
.WaitAndRetryAsync(7, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
var circuitBreaker = HttpPolicyExtensions
.HandleTransientHttpError()
.CircuitBreakerAsync(6, TimeSpan.FromSeconds(30));
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
services.AddHttpClient<IBasketService, BasketService>()
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()


+ 2
- 2
src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs View File

@ -154,11 +154,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
.HandleTransientHttpError()
.Or<TimeoutRejectedException>()
.OrResult(message => message.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(7, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
var circuitBreaker = HttpPolicyExtensions
.HandleTransientHttpError()
.CircuitBreakerAsync(6, TimeSpan.FromSeconds(30));
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
services.AddHttpClient<IBasketService, BasketService>()
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()


+ 0
- 74
src/Web/WebMVC/Infrastructure/HttpClientDefaultPolicies.cs View File

@ -1,74 +0,0 @@
using Microsoft.Extensions.Logging;
using Polly;
using Polly.CircuitBreaker;
using Polly.Retry;
using System;
using System.Net.Http;
namespace WebMVC.Infrastructure
{
public class HttpClientDefaultPolicies
{
//Config for Retries with exponential backoff policy
const int MAX_RETRIES = 6;
const int SECONDS_BASE_FOR_EXPONENTIAL_BACKOFF = 2;
//Config for Circuit Breaker policy
const int EXCEPTIONS_ALLOWED_BEFORE_CIRCUIT_BREAKES = 5;
const int DURATION_OF_BREAK_IN_MINUTES = 1;
private readonly ILogger<HttpClientDefaultPolicies> _logger;
public HttpClientDefaultPolicies(ILogger<HttpClientDefaultPolicies> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public IAsyncPolicy<HttpResponseMessage> GetWaitAndRetryPolicy()
{
RetryPolicy retryPolicy =
Policy.Handle<HttpRequestException>()
.WaitAndRetryAsync(
// Maximum number of retries
MAX_RETRIES,
// exponential backofff (2sg, 4sg, 8sg, 16sg, 32sg. etc.)
retryAttempt => TimeSpan.FromSeconds(Math.Pow(SECONDS_BASE_FOR_EXPONENTIAL_BACKOFF, retryAttempt)),
// on retry
(exception, timeSpan, retryCount, context) =>
{
var msg = $"Retry {retryCount} implemented with Polly's RetryPolicy " +
$"of {context.PolicyKey} " +
$"at {context.OperationKey}, " +
$"due to: {exception}.";
_logger.LogWarning(msg);
_logger.LogDebug(msg);
});
return retryPolicy.AsAsyncPolicy<HttpResponseMessage>();
}
public IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
{
CircuitBreakerPolicy circuitBreakerPolicy =
Policy.Handle<HttpRequestException>()
.CircuitBreakerAsync(
// Number of exceptions before breaking the circuit
EXCEPTIONS_ALLOWED_BEFORE_CIRCUIT_BREAKES,
// Duration of break
TimeSpan.FromMinutes(DURATION_OF_BREAK_IN_MINUTES),
(exception, duration) =>
{
// On circuit opened (Circuit is broken)
_logger.LogTrace("Circuit has been broken");
},
() =>
{
// on circuit closed
_logger.LogTrace("Circuit has been reset");
});
return circuitBreakerPolicy.AsAsyncPolicy<HttpResponseMessage>();
}
}
}

+ 2
- 2
src/Web/WebMVC/Startup.cs View File

@ -174,11 +174,11 @@ namespace Microsoft.eShopOnContainers.WebMVC
var retriesWithExponentialBackoff = HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg=>msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(5,retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
.WaitAndRetryAsync(6,retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
var circuitBreaker = HttpPolicyExtensions
.HandleTransientHttpError()
.CircuitBreakerAsync(6, TimeSpan.FromSeconds(30));
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
//register delegating handlers
services.AddTransient<HttpClientAuthorizationDelegatingHandler>();


Loading…
Cancel
Save