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. } }
public void Handle(Message message, IBusForHandler bus) { bus.Postpone(new PostponedMessage(), ScheduledEnqueTimeUtc).Wait(); }
public async Task Handle(Message message, IBusForHandler bus) { await bus.Postpone(new PostponedMessage(), ScheduledEnqueTimeUtc); }