public async Task Invoke(IncomingLogicalContext context, IBusForHandler bus, Func <Task> next)
        {
            ExceptionDispatchInfo exceptionDispatchInfo = null;

            try
            {
                await next()
                .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                if (ShouldMessageBeDelayed(context))
                {
                    // We can't do async in a catch block, therefore we have to capture the exception!
                    exceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception);
                }
                else
                {
                    throw;
                }
            }

            if (exceptionDispatchInfo != null)
            {
                var message = context.TransportMessage;
                var scheduledEnqueueTimeUtc = DateTime.UtcNow
                                              + TimeSpan.FromSeconds(DelayTimeSpanInSeconds(context));

                message.DelayedDeliveryCount++;
                await bus.Postpone(context.LogicalMessage.Instance, scheduledEnqueueTimeUtc);

                // Don't rethrow, the current message is consumed and a new message is postponed.
            }
        }
コード例 #2
0
 public void Handle(Message message, IBusForHandler bus)
 {
     bus.Postpone(new PostponedMessage(), ScheduledEnqueTimeUtc).Wait();
 }
コード例 #3
0
 public async Task Handle(Message message, IBusForHandler bus)
 {
     await bus.Postpone(new PostponedMessage(), ScheduledEnqueTimeUtc);
 }