Browse Source

Merge pull request #9669 from abpframework/liangshiwei/eventbus

Remove IJsonSerializer use in LocalEventBus
pull/9670/head
maliming 5 years ago
committed by GitHub
parent
commit
23600fa76a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs
  2. 3
      framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Exception_Handler_Tests.cs

9
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs

@ -30,17 +30,13 @@ namespace Volo.Abp.EventBus.Local
protected ConcurrentDictionary<Type, List<IEventHandlerFactory>> HandlerFactories { get; }
protected IJsonSerializer Serializer { get; }
public LocalEventBus(
IOptions<AbpLocalEventBusOptions> options,
IServiceScopeFactory serviceScopeFactory,
ICurrentTenant currentTenant,
IEventErrorHandler errorHandler,
IJsonSerializer serializer)
IEventErrorHandler errorHandler)
: base(serviceScopeFactory, currentTenant, errorHandler)
{
Serializer = serializer;
Options = options.Value;
Logger = NullLogger<LocalEventBus>.Instance;
@ -131,10 +127,9 @@ namespace Volo.Abp.EventBus.Local
public virtual async Task PublishAsync(LocalEventMessage localEventMessage)
{
var rawEventData = Serializer.Serialize(localEventMessage.EventData);
await TriggerHandlersAsync(localEventMessage.EventType, localEventMessage.EventData, errorContext =>
{
errorContext.EventData = Serializer.Deserialize(localEventMessage.EventType, rawEventData);
errorContext.EventData = localEventMessage.EventData;
errorContext.SetProperty(nameof(LocalEventMessage.MessageId), localEventMessage.MessageId);
});
}

3
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Local/EventBus_Exception_Handler_Tests.cs

@ -33,9 +33,7 @@ namespace Volo.Abp.EventBus.Local
LocalEventBus.Subscribe<MyExceptionHandleEventData>(eventData =>
{
eventData.Value.ShouldBe(0);
retryAttempt++;
eventData.Value++;
if (retryAttempt < 2)
{
throw new Exception("This exception is intentionally thrown!");
@ -58,7 +56,6 @@ namespace Volo.Abp.EventBus.Local
eventData.Value.ShouldBe(0);
retryAttempt++;
eventData.Value++;
throw new Exception("This exception is intentionally thrown!");
});

Loading…
Cancel
Save