Browse Source

Using asynchronous methods

pull/8829/head
liangshiwei 5 years ago
parent
commit
abc400ce9b
  1. 4
      framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs
  2. 4
      framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqEventErrorHandler.cs
  3. 4
      framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusEventErrorHandler.cs
  4. 2
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventBusBase.cs
  5. 28
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/EventErrorHandlerBase.cs
  6. 2
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/IEventErrorHandler.cs
  7. 8
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventErrorHandler.cs

4
framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaEventErrorHandler.cs

@ -21,7 +21,7 @@ namespace Volo.Abp.EventBus.Kafka
Logger = NullLogger<KafkaEventErrorHandler>.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<string, object> {{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),

4
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);

4
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);

2
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);
}
}

28
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<bool> 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<bool> 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)

2
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);
}
}

8
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventErrorHandler.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.EventBus.Local
RetryTracking = new Dictionary<Guid, int>();
}
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<bool> ShouldRetryAsync(EventExecutionErrorContext context)
{
var messageId = context.GetProperty<Guid>(nameof(LocalEventMessage.MessageId));
context.SetProperty(RetryAttemptKey, RetryTracking.GetOrDefault(messageId));
if (base.ShouldRetry(context))
if (await base.ShouldRetryAsync(context))
{
return true;
}

Loading…
Cancel
Save