Using asynchronous methods

pull/8829/head
liangshiwei 4 years ago
parent 450f52e18a
commit abc400ce9b

@ -21,7 +21,7 @@ namespace Volo.Abp.EventBus.Kafka
Logger = NullLogger<KafkaEventErrorHandler>.Instance; Logger = NullLogger<KafkaEventErrorHandler>.Instance;
} }
protected override async Task Retry(EventExecutionErrorContext context) protected override async Task RetryAsync(EventExecutionErrorContext context)
{ {
if (Options.RetryStrategyOptions.IntervalMillisecond > 0) if (Options.RetryStrategyOptions.IntervalMillisecond > 0)
{ {
@ -37,7 +37,7 @@ namespace Volo.Abp.EventBus.Kafka
new Dictionary<string, object> {{RetryAttemptKey, ++retryAttempt}}); new Dictionary<string, object> {{RetryAttemptKey, ++retryAttempt}});
} }
protected override async Task MoveToDeadLetter(EventExecutionErrorContext context) protected override async Task MoveToDeadLetterAsync(EventExecutionErrorContext context)
{ {
Logger.LogException( Logger.LogException(
context.Exceptions.Count == 1 ? context.Exceptions.First() : new AggregateException(context.Exceptions), context.Exceptions.Count == 1 ? context.Exceptions.First() : new AggregateException(context.Exceptions),

@ -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) 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); ThrowOriginalExceptions(context);

@ -15,14 +15,14 @@ namespace Volo.Abp.EventBus.Rebus
{ {
} }
protected override Task Retry(EventExecutionErrorContext context) protected override Task RetryAsync(EventExecutionErrorContext context)
{ {
ThrowOriginalExceptions(context); ThrowOriginalExceptions(context);
return Task.CompletedTask; return Task.CompletedTask;
} }
protected override Task MoveToDeadLetter(EventExecutionErrorContext context) protected override Task MoveToDeadLetterAsync(EventExecutionErrorContext context)
{ {
ThrowOriginalExceptions(context); ThrowOriginalExceptions(context);

@ -105,7 +105,7 @@ namespace Volo.Abp.EventBus
{ {
var context = new EventExecutionErrorContext(exceptions, eventType, this); var context = new EventExecutionErrorContext(exceptions, eventType, this);
onErrorAction?.Invoke(context); onErrorAction?.Invoke(context);
await ErrorHandler.Handle(context); await ErrorHandler.HandleAsync(context);
} }
} }

@ -16,49 +16,49 @@ namespace Volo.Abp.EventBus
Options = options.Value; 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); ThrowOriginalExceptions(context);
} }
if (ShouldRetry(context)) if (await ShouldRetryAsync(context))
{ {
await Retry(context); await RetryAsync(context);
return; 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<bool> ShouldHandleAsync(EventExecutionErrorContext context)
{ {
if (!Options.EnabledErrorHandle) 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<bool> ShouldRetryAsync(EventExecutionErrorContext context)
{ {
if (Options.RetryStrategyOptions == null) if (Options.RetryStrategyOptions == null)
{ {
return false; return Task.FromResult(false);
} }
if (!context.TryGetRetryAttempt(out var retryAttempt)) 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) protected virtual void ThrowOriginalExceptions(EventExecutionErrorContext context)

@ -4,6 +4,6 @@ namespace Volo.Abp.EventBus
{ {
public interface IEventErrorHandler public interface IEventErrorHandler
{ {
Task Handle(EventExecutionErrorContext context); Task HandleAsync(EventExecutionErrorContext context);
} }
} }

@ -19,7 +19,7 @@ namespace Volo.Abp.EventBus.Local
RetryTracking = new Dictionary<Guid, int>(); RetryTracking = new Dictionary<Guid, int>();
} }
protected override async Task Retry(EventExecutionErrorContext context) protected override async Task RetryAsync(EventExecutionErrorContext context)
{ {
if (Options.RetryStrategyOptions.IntervalMillisecond > 0) if (Options.RetryStrategyOptions.IntervalMillisecond > 0)
{ {
@ -36,19 +36,19 @@ namespace Volo.Abp.EventBus.Local
RetryTracking.Remove(messageId); RetryTracking.Remove(messageId);
} }
protected override Task MoveToDeadLetter(EventExecutionErrorContext context) protected override Task MoveToDeadLetterAsync(EventExecutionErrorContext context)
{ {
ThrowOriginalExceptions(context); ThrowOriginalExceptions(context);
return Task.CompletedTask; return Task.CompletedTask;
} }
protected override bool ShouldRetry(EventExecutionErrorContext context) protected override async Task<bool> ShouldRetryAsync(EventExecutionErrorContext context)
{ {
var messageId = context.GetProperty<Guid>(nameof(LocalEventMessage.MessageId)); var messageId = context.GetProperty<Guid>(nameof(LocalEventMessage.MessageId));
context.SetProperty(RetryAttemptKey, RetryTracking.GetOrDefault(messageId)); context.SetProperty(RetryAttemptKey, RetryTracking.GetOrDefault(messageId));
if (base.ShouldRetry(context)) if (await base.ShouldRetryAsync(context))
{ {
return true; return true;
} }

Loading…
Cancel
Save