From 4cd2c86bd6b79cf041bb0d72ad29a5f442b4237f Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 6 Jan 2022 20:12:18 +0800 Subject: [PATCH] Handle the exception in `InboxProcessor` and `OutboxSender`. --- .../EventBus/Distributed/InboxProcessor.cs | 24 ++++++++++++------- .../Abp/EventBus/Distributed/OutboxSender.cs | 24 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs index 6a25804e74..bb1fbca4c6 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs @@ -102,18 +102,26 @@ namespace Volo.Abp.EventBus.Boxes foreach (var waitingEvent in waitingEvents) { - using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true)) + try { - await DistributedEventBus - .AsSupportsEventBoxes() - .ProcessFromInboxAsync(waitingEvent, InboxConfig); + using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true)) + { + await DistributedEventBus + .AsSupportsEventBoxes() + .ProcessFromInboxAsync(waitingEvent, InboxConfig); - await Inbox.MarkAsProcessedAsync(waitingEvent.Id); + await Inbox.MarkAsProcessedAsync(waitingEvent.Id); - await uow.CompleteAsync(); - } + await uow.CompleteAsync(StoppingToken); - Logger.LogInformation($"Processed the incoming event with id = {waitingEvent.Id:N}"); + Logger.LogInformation($"Processed the incoming event with id = {waitingEvent.Id:N}"); + } + } + catch (Exception e) + { + Logger.LogError($"An exception occurred when processed the incoming event with id = {waitingEvent.Id:N}"); + Logger.LogException(e); + } } } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs index 873878bca7..7c39354867 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs @@ -85,15 +85,23 @@ namespace Volo.Abp.EventBus.Boxes foreach (var waitingEvent in waitingEvents) { - await DistributedEventBus - .AsSupportsEventBoxes() - .PublishFromOutboxAsync( - waitingEvent, - OutboxConfig - ); + try + { + await DistributedEventBus + .AsSupportsEventBoxes() + .PublishFromOutboxAsync( + waitingEvent, + OutboxConfig + ); - await Outbox.DeleteAsync(waitingEvent.Id); - Logger.LogInformation($"Sent the event to the message broker with id = {waitingEvent.Id:N}"); + await Outbox.DeleteAsync(waitingEvent.Id); + Logger.LogInformation($"Sent the event to the message broker with id = {waitingEvent.Id:N}"); + } + catch (Exception e) + { + Logger.LogError($"An exception occurred when sent the event to the message broker with id = {waitingEvent.Id:N}"); + Logger.LogException(e); + } } } }