From abc400ce9b65cd46930c538817b1222a2ebbe812 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 17 Jun 2021 10:18:30 +0800 Subject: [PATCH] Using asynchronous methods --- .../EventBus/Kafka/KafkaEventErrorHandler.cs | 4 +-- .../RabbitMq/RabbitMqEventErrorHandler.cs | 4 +-- .../EventBus/Rebus/RebusEventErrorHandler.cs | 4 +-- .../Volo/Abp/EventBus/EventBusBase.cs | 2 +- .../Abp/EventBus/EventErrorHandlerBase.cs | 28 +++++++++---------- .../Volo/Abp/EventBus/IEventErrorHandler.cs | 2 +- .../EventBus/Local/LocalEventErrorHandler.cs | 8 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs index 774973c649..aee21f75a9 100644 --- a/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs +++ b/framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs @@ -21,7 +21,7 @@ namespace Volo.Abp.EventBus.Kafka Logger = NullLogger.Instance; } - protected override async Task Retry(EventExecutionErrorContext context) + protected override async Task RetryAsync(EventExecutionErrorContext context) { if (Options.RetryStrategyOptions.IntervalMillisecond > 0) { @@ -37,7 +37,7 @@ namespace Volo.Abp.EventBus.Kafka new Dictionary {{RetryAttemptKey, ++retryAttempt}}); } - protected override async Task MoveToDeadLetter(EventExecutionErrorContext context) + protected override async Task MoveToDeadLetterAsync(EventExecutionErrorContext context) { Logger.LogException( context.Exceptions.Count == 1 ? context.Exceptions.First() : new AggregateException(context.Exceptions), diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqEventErrorHandler.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqEventErrorHandler.cs index 1a7a10dcae..e8848bee72 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqEventErrorHandler.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqEventErrorHandler.cs @@ -17,7 +17,7 @@ namespace Volo.Abp.EventBus.RabbitMq { } - protected override async Task Retry(EventExecutionErrorContext context) + protected override async Task RetryAsync(EventExecutionErrorContext context) { if (Options.RetryStrategyOptions.IntervalMillisecond > 0) { @@ -37,7 +37,7 @@ namespace Volo.Abp.EventBus.RabbitMq }); } - protected override Task MoveToDeadLetter(EventExecutionErrorContext context) + protected override Task MoveToDeadLetterAsync(EventExecutionErrorContext context) { ThrowOriginalExceptions(context); diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusEventErrorHandler.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusEventErrorHandler.cs index 186fb5b5fc..8fe6a53dbb 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusEventErrorHandler.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusEventErrorHandler.cs @@ -15,14 +15,14 @@ namespace Volo.Abp.EventBus.Rebus { } - protected override Task Retry(EventExecutionErrorContext context) + protected override Task RetryAsync(EventExecutionErrorContext context) { ThrowOriginalExceptions(context); return Task.CompletedTask; } - protected override Task MoveToDeadLetter(EventExecutionErrorContext context) + protected override Task MoveToDeadLetterAsync(EventExecutionErrorContext context) { ThrowOriginalExceptions(context); diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs index df477df609..78d226538e 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs @@ -105,7 +105,7 @@ namespace Volo.Abp.EventBus { var context = new EventExecutionErrorContext(exceptions, eventType, this); onErrorAction?.Invoke(context); - await ErrorHandler.Handle(context); + await ErrorHandler.HandleAsync(context); } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventErrorHandlerBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventErrorHandlerBase.cs index c557e3c85c..ba4527fc70 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventErrorHandlerBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventErrorHandlerBase.cs @@ -16,49 +16,49 @@ namespace Volo.Abp.EventBus Options = options.Value; } - public virtual async Task Handle(EventExecutionErrorContext context) + public virtual async Task HandleAsync(EventExecutionErrorContext context) { - if (!ShouldHandle(context)) + if (!await ShouldHandleAsync(context)) { ThrowOriginalExceptions(context); } - if (ShouldRetry(context)) + if (await ShouldRetryAsync(context)) { - await Retry(context); + await RetryAsync(context); return; } - await MoveToDeadLetter(context); + await MoveToDeadLetterAsync(context); } - protected abstract Task Retry(EventExecutionErrorContext context); + protected abstract Task RetryAsync(EventExecutionErrorContext context); - protected abstract Task MoveToDeadLetter(EventExecutionErrorContext context); + protected abstract Task MoveToDeadLetterAsync(EventExecutionErrorContext context); - protected virtual bool ShouldHandle(EventExecutionErrorContext context) + protected virtual Task ShouldHandleAsync(EventExecutionErrorContext context) { if (!Options.EnabledErrorHandle) { - return false; + return Task.FromResult(false); } - return Options.ErrorHandleSelector == null || Options.ErrorHandleSelector.Invoke(context.EventType); + return Task.FromResult(Options.ErrorHandleSelector == null || Options.ErrorHandleSelector.Invoke(context.EventType)); } - protected virtual bool ShouldRetry(EventExecutionErrorContext context) + protected virtual Task ShouldRetryAsync(EventExecutionErrorContext context) { if (Options.RetryStrategyOptions == null) { - return false; + return Task.FromResult(false); } if (!context.TryGetRetryAttempt(out var retryAttempt)) { - return false; + return Task.FromResult(false); } - return Options.RetryStrategyOptions.MaxRetryAttempts > retryAttempt; + return Task.FromResult(Options.RetryStrategyOptions.MaxRetryAttempts > retryAttempt); } protected virtual void ThrowOriginalExceptions(EventExecutionErrorContext context) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IEventErrorHandler.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IEventErrorHandler.cs index 27d4951ead..f1b4a40f15 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IEventErrorHandler.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IEventErrorHandler.cs @@ -4,6 +4,6 @@ namespace Volo.Abp.EventBus { public interface IEventErrorHandler { - Task Handle(EventExecutionErrorContext context); + Task HandleAsync(EventExecutionErrorContext context); } } diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventErrorHandler.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventErrorHandler.cs index 662406a720..c08bca019f 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventErrorHandler.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventErrorHandler.cs @@ -19,7 +19,7 @@ namespace Volo.Abp.EventBus.Local RetryTracking = new Dictionary(); } - protected override async Task Retry(EventExecutionErrorContext context) + protected override async Task RetryAsync(EventExecutionErrorContext context) { if (Options.RetryStrategyOptions.IntervalMillisecond > 0) { @@ -36,19 +36,19 @@ namespace Volo.Abp.EventBus.Local RetryTracking.Remove(messageId); } - protected override Task MoveToDeadLetter(EventExecutionErrorContext context) + protected override Task MoveToDeadLetterAsync(EventExecutionErrorContext context) { ThrowOriginalExceptions(context); return Task.CompletedTask; } - protected override bool ShouldRetry(EventExecutionErrorContext context) + protected override async Task ShouldRetryAsync(EventExecutionErrorContext context) { var messageId = context.GetProperty(nameof(LocalEventMessage.MessageId)); context.SetProperty(RetryAttemptKey, RetryTracking.GetOrDefault(messageId)); - if (base.ShouldRetry(context)) + if (await base.ShouldRetryAsync(context)) { return true; }