Beispiel #1
0
        public Task Send(ConsumeContext <TData> context)
        {
            using (RetryPolicyContext <ConsumeContext <TData> > policyContext = _retryPolicy.CreatePolicyContext(context))
            {
                var exception = new SagaException("An existing saga instance was not found", typeof(TInstance), typeof(TData), context.CorrelationId ?? Guid
                                                  .Empty);

                if (!policyContext.CanRetry(exception, out RetryContext <ConsumeContext <TData> > retryContext))
                {
                    return(_finalPipe.Send(context));
                }

                int previousDeliveryCount = context.GetRedeliveryCount();
                for (int retryIndex = 0; retryIndex < previousDeliveryCount; retryIndex++)
                {
                    if (!retryContext.CanRetry(exception, out retryContext))
                    {
                        return(_finalPipe.Send(context));
                    }
                }

                var schedulerContext = context.GetPayload <MessageSchedulerContext>();

                MessageRedeliveryContext redeliveryContext = new ScheduleMessageRedeliveryContext <TData>(context, schedulerContext);

                var delay = retryContext.Delay ?? TimeSpan.Zero;

                return(redeliveryContext.ScheduleRedelivery(delay));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Redeliver uses the message scheduler to deliver the message to the queue at a future
        /// time. The delivery count is incremented. Moreover, if you give custom callback action, it perform before sending message to queue.
        /// A message scheduler must be configured on the bus for redelivery to be enabled.
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <param name="context">The consume context of the message</param>
        /// <param name="delay">
        /// The delay before the message is delivered. It may take longer to receive the message if the queue is not empty.
        /// </param>
        /// <param name="callback">Operation which is executed before the message is delivered.</param>
        /// <returns></returns>
        public static Task Redeliver <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null)
            where T : class
        {
            MessageRedeliveryContext redeliverContext = new ScheduleMessageRedeliveryContext <T>(context);

            return(redeliverContext.ScheduleRedelivery(delay, callback));
        }
Beispiel #3
0
        /// <summary>
        /// Redeliver uses the message scheduler to deliver the message to the queue at a future
        /// time. The delivery count is incremented. Moreover, if you give custom callback action, it perform before sending message to queueu.
        /// A message scheduler must be configured on the bus for redelivery to be enabled.
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <param name="context">The consume context of the message</param>
        /// <param name="delay">The delay before the message is delivered. It may take longer to receive the message if the queue is not empty.</param>
        /// <param name="callback">Operation which is executed before the message is delivered.</param>
        /// <returns></returns>
        public static Task Redeliver <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null)
            where T : class
        {
            if (!context.TryGetPayload(out MessageSchedulerContext schedulerContext))
            {
                throw new MessageException(typeof(T), "No scheduler context was available to redeliver the message");
            }

            MessageRedeliveryContext redeliverContext = new ScheduleMessageRedeliveryContext <T>(context, schedulerContext);

            return(redeliverContext.ScheduleRedelivery(delay, callback));
        }