Browse Source

Add error handling to InboxProcessor event processing

Wrapped event processing in a try-catch block to log errors when processing individual events fails. This prevents one failed event from interrupting the processing of subsequent events and improves reliability.
pull/23563/head
maliming 1 year ago
parent
commit
d7dd915d76
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 23
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs

23
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs

@ -103,18 +103,25 @@ public class InboxProcessor : IInboxProcessor, ITransientDependency
foreach (var waitingEvent in waitingEvents) foreach (var waitingEvent in waitingEvents)
{ {
using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true)) try
{ {
await DistributedEventBus using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true))
.AsSupportsEventBoxes() {
.ProcessFromInboxAsync(waitingEvent, InboxConfig); await DistributedEventBus
.AsSupportsEventBoxes()
.ProcessFromInboxAsync(waitingEvent, InboxConfig);
await Inbox.MarkAsProcessedAsync(waitingEvent.Id); await Inbox.MarkAsProcessedAsync(waitingEvent.Id);
await uow.CompleteAsync(StoppingToken); 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(e, $"An error occurred while processing the incoming event with id = {waitingEvent.Id:N}");
}
} }
} }
} }

Loading…
Cancel
Save