/// <summary>
        /// Create an interval retry policy with the specified intervals. The retry count equals
        /// the number of intervals provided
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="intervals">The intervals before each subsequent retry attempt</param>
        /// <returns></returns>
        public static IRetryConfigurator Intervals(this IRetryConfigurator configurator, params int[] intervals)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            configurator.SetRetryPolicy(filter => new IntervalRetryPolicy(filter, intervals));

            return(configurator);
        }
        /// <summary>
        /// Create an immediate retry policy with the specified number of retries, with no
        /// delay between attempts.
        /// </summary>
        /// <param name="configurator"></param>
        /// <returns></returns>
        public static IRetryConfigurator None(this IRetryConfigurator configurator)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            configurator.SetRetryPolicy(filter => new NoRetryPolicy(filter));

            return(configurator);
        }
        /// <summary>
        /// Create an immediate retry policy with the specified number of retries, with no
        /// delay between attempts.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="retryLimit">The number of retries to attempt</param>
        /// <returns></returns>
        public static IRetryConfigurator Immediate(this IRetryConfigurator configurator, int retryLimit)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            configurator.SetRetryPolicy(filter => new ImmediateRetryPolicy(filter, retryLimit));

            return(configurator);
        }
        /// <summary>
        /// Create an interval retry policy with the specified number of retries at a fixed interval
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="retryCount">The number of retry attempts</param>
        /// <param name="interval">The interval between each retry attempt</param>
        /// <returns></returns>
        public static IRetryConfigurator Interval(this IRetryConfigurator configurator, int retryCount, int interval)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            configurator.SetRetryPolicy(filter => new IntervalRetryPolicy(filter, Enumerable.Repeat(interval, retryCount).ToArray()));

            return(configurator);
        }
        /// <summary>
        /// Create an incremental retry policy with the specified number of retry attempts with an incrementing
        /// interval between retries
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="retryLimit">The number of retry attempts</param>
        /// <param name="initialInterval">The initial retry interval</param>
        /// <param name="intervalIncrement">The interval to add to the retry interval with each subsequent retry</param>
        /// <returns></returns>
        public static IRetryConfigurator Incremental(this IRetryConfigurator configurator, int retryLimit, TimeSpan initialInterval, TimeSpan intervalIncrement)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            configurator.SetRetryPolicy(filter => new IncrementalRetryPolicy(filter, retryLimit, initialInterval, intervalIncrement));

            return(configurator);
        }
        public static IRetryConfigurator UseDefaultFirstLevelRetriesIntervals(this IRetryConfigurator configurator)
        {
            configurator.Intervals(
                TimeSpan.FromMilliseconds(0),
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(200),
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(3));

            return(configurator);
        }
        public static IRetryConfigurator UseDefaultSecondLevelRetriesIntervals(this IRetryConfigurator configurator)
        {
            configurator.Intervals(
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(30),
                TimeSpan.FromSeconds(60),
                TimeSpan.FromMinutes(10),
                TimeSpan.FromMinutes(30));

            return(configurator);
        }
        /// <summary>
        /// Create an exponential retry policy with the specified number of retries at exponential
        /// intervals
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="retryLimit"></param>
        /// <param name="minInterval"></param>
        /// <param name="maxInterval"></param>
        /// <param name="intervalDelta"></param>
        /// <returns></returns>
        public static IRetryConfigurator Exponential(this IRetryConfigurator configurator, int retryLimit, TimeSpan minInterval, TimeSpan maxInterval,
                                                     TimeSpan intervalDelta)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            configurator.SetRetryPolicy(filter => new ExponentialRetryPolicy(filter, retryLimit, minInterval, maxInterval, intervalDelta));

            return(configurator);
        }
 public static void ConfigureDefaultRetryPolicy(IRetryConfigurator retryPolicy)
 {
     retryPolicy.Exponential(10, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5));
 }
Пример #10
0
        public static IRetryConfigurator AddRetriesAudit(this IRetryConfigurator configurator, IServiceProvider provider)
        {
            configurator.ConnectRetryObserver(provider.GetRequiredService <MessageRetryAuditObserver>());

            return(configurator);
        }
Пример #11
0
 private static void RetryPolicy(IRetryConfigurator retry)
 {
     //retry.Exponential(5, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(5));
     retry.Interval(5, TimeSpan.FromSeconds(1));
 }