예제 #1
0
        public HttpClientPollyPolicy AddWaitRetryPolicy(int retryCount)
        {
            if (!_policies.ContainsKey(RetryKey))
            {
                var policy = HttpClientPolicyBuilder.WaitAndRetryAsync(retryCount, ExponentialBackoffTimespan)
                             .WithPolicyKey(RetryKey);

                _policies.Add(RetryKey, policy);
            }

            return(this);
        }
예제 #2
0
        public HttpClientPollyPolicy AddFallbackPolicy(Func <Task <HttpResponseMessage> > action)
        {
            if (!_policies.ContainsKey(FallbackKey))
            {
                var policy = HttpClientPolicyBuilder
                             .Or <TimeoutRejectedException>()
                             .Or <BrokenCircuitException>()
                             .FallbackAsync(cancellationToken => action())
                             .WithPolicyKey(FallbackKey);

                _policies.Add(FallbackKey, policy);
            }

            return(this);
        }