Exemplo n.º 1
0
        public PollyWithInternalServerErrorCircuitBreakingDelegatingHandler(DownstreamRoute route, IOcelotLoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger <PollyWithInternalServerErrorCircuitBreakingDelegatingHandler>();

            var pollyQosProvider = new PollyQoSProvider(route, loggerFactory);

            var responsePolicy = Policy.HandleResult <HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.InternalServerError)
                                 .CircuitBreakerAsync(route.QosOptions.ExceptionsAllowedBeforeBreaking,
                                                      TimeSpan.FromMilliseconds(route.QosOptions.DurationOfBreak));

            _circuitBreakerPolicies = Policy.WrapAsync(pollyQosProvider.CircuitBreaker.Policies)
                                      .WrapAsync(responsePolicy);
        }
Exemplo n.º 2
0
        public void should_build()
        {
            var options = new QoSOptionsBuilder()
                          .WithTimeoutValue(100)
                          .WithExceptionsAllowedBeforeBreaking(1)
                          .WithDurationOfBreak(200)
                          .Build();
            var route = new DownstreamRouteBuilder().WithQosOptions(options)
                        .Build();
            var factory          = new Mock <IOcelotLoggerFactory>();
            var pollyQoSProvider = new PollyQoSProvider(route, factory.Object);

            pollyQoSProvider.CircuitBreaker.ShouldNotBeNull();
        }