コード例 #1
0
        internal static HedgingPolicyInfo CreateHedgingPolicy(HedgingPolicy h)
        {
            if (!(h.MaxAttempts > 1))
            {
                throw new InvalidOperationException("Hedging policy max attempts must be greater than 1.");
            }
            if (h.HedgingDelay != null && h.HedgingDelay < TimeSpan.Zero)
            {
                throw new InvalidOperationException("Hedging policy delay must be equal or greater than zero.");
            }

            return(new HedgingPolicyInfo
            {
                MaxAttempts = h.MaxAttempts.GetValueOrDefault(),
                HedgingDelay = h.HedgingDelay.GetValueOrDefault(),
                NonFatalStatusCodes = h.NonFatalStatusCodes.ToList()
            });
        }
コード例 #2
0
        public static ServiceConfig CreateHedgingServiceConfig(
            int?maxAttempts       = null,
            TimeSpan?hedgingDelay = null,
            IList <StatusCode>?nonFatalStatusCodes = null,
            RetryThrottlingPolicy?retryThrottling  = null)
        {
            var hedgingPolicy = new HedgingPolicy
            {
                MaxAttempts  = maxAttempts ?? 5,
                HedgingDelay = hedgingDelay ?? TimeSpan.Zero
            };

            if (nonFatalStatusCodes != null)
            {
                foreach (var statusCode in nonFatalStatusCodes)
                {
                    hedgingPolicy.NonFatalStatusCodes.Add(statusCode);
                }
            }
            else
            {
                hedgingPolicy.NonFatalStatusCodes.Add(StatusCode.Unavailable);
            }

            return(new ServiceConfig
            {
                MethodConfigs =
                {
                    new MethodConfig
                    {
                        Names ={ MethodName.Default             },
                        HedgingPolicy = hedgingPolicy
                    }
                },
                RetryThrottling = retryThrottling
            });
        }