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
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
1 changed files with
15 additions and
8 deletions
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 )
{
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 ( 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}" ) ;
}
}
}
}