public ConsumeContextRetryPolicyContext(RetryPolicyContext <ConsumeContext> policyContext, RetryConsumeContext context,
                                         CancellationToken cancellationToken)
 {
     _policyContext     = policyContext;
     _context           = context;
     _cancellationToken = cancellationToken;
 }
示例#2
0
        async Task Attempt(RetryConsumeContext context, IPipe <ConsumeContext> next)
        {
            context.ClearPendingFaults();

            TimeSpan delay;

            try
            {
                await next.Send(context).ConfigureAwait(false);

                return;
            }
            catch (Exception ex)
            {
                if (!_retryPolicy.CanRetry(ex))
                {
                    context.NotifyPendingFaults();
                    throw;
                }

                // by not adding the retry payload until the exception occurs, the deepest retry filter
                // is the one to set the actual retry context with the deepest configured policy
                IRetryContext retryContext = context.GetOrAddPayload(() => _retryPolicy.GetRetryContext());
                if (!retryContext.CanRetry(ex, out delay))
                {
                    context.NotifyPendingFaults();
                    throw;
                }
            }

            await Task.Delay(delay).ConfigureAwait(false);

            await Attempt(context, next).ConfigureAwait(false);
        }
示例#3
0
        public ConsumeContextRetryContext(RetryContext <ConsumeContext> retryContext, RetryConsumeContext context)
        {
            _retryContext = retryContext;
            _context      = context;

            _context.RetryAttempt = retryContext.RetryCount;
        }
        RetryPolicyContext <T> IRetryPolicy.CreatePolicyContext <T>(T context)
        {
            if (context is ConsumeContext consumeContext)
            {
                RetryPolicyContext <ConsumeContext> retryPolicyContext = _retryPolicy.CreatePolicyContext(consumeContext);

                var retryConsumeContext = new RetryConsumeContext(consumeContext);

                return(new ConsumeContextRetryPolicyContext(retryPolicyContext, retryConsumeContext) as RetryPolicyContext <T>);
            }

            throw new ArgumentException("The argument must be a ConsumeContext", nameof(context));
        }
 public ConsumeContextRetryPolicyContext(RetryPolicyContext <ConsumeContext> policyContext, RetryConsumeContext context)
 {
     _policyContext = policyContext;
     _context       = context;
 }
 public ConsumeContextRetryContext(RetryContext <ConsumeContext> retryContext, RetryConsumeContext context)
 {
     _retryContext = retryContext;
     _context      = context;
 }
示例#7
0
        Task IFilter <ConsumeContext> .Send(ConsumeContext context, IPipe <ConsumeContext> next)
        {
            var retryContext = new RetryConsumeContext(context);

            return(Attempt(retryContext, next));
        }
示例#8
0
        async Task IFilter <ConsumeContext> .Send(ConsumeContext context, IPipe <ConsumeContext> next)
        {
            var retryContext = new RetryConsumeContext(context);

            await Attempt(retryContext, next).ConfigureAwait(false);
        }