From e3542fd102dd0bdfc51e452eb07ca66462b39bf4 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 23 Jan 2025 17:15:47 +0800 Subject: [PATCH] Publish `DistributedEventSentReceived` events first. --- .../Distributed/LocalDistributedEventBus.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs index 7315063214..337c54db33 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs @@ -125,47 +125,48 @@ public class LocalDistributedEventBus : IDistributedEventBus, ISingletonDependen public async Task PublishAsync(TEvent eventData, bool onUnitOfWorkComplete = true) where TEvent : class { - await _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete); await PublishDistributedEventSentReceivedAsync(typeof(TEvent), eventData, onUnitOfWorkComplete); + await _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete); } public async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true) { - await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); await PublishDistributedEventSentReceivedAsync(eventType, eventData, onUnitOfWorkComplete); + await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); } public async Task PublishAsync(TEvent eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) where TEvent : class { - await _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete); await PublishDistributedEventSentReceivedAsync(typeof(TEvent), eventData, onUnitOfWorkComplete); + await _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete); } public async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) { - await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); await PublishDistributedEventSentReceivedAsync(eventType, eventData, onUnitOfWorkComplete); + await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); } private async Task PublishDistributedEventSentReceivedAsync(Type eventType, object eventData, bool onUnitOfWorkComplete) { - if (eventType == typeof(DistributedEventSent) || eventType == typeof(DistributedEventReceived)) + if (eventType != typeof(DistributedEventSent)) { - return; + await _localEventBus.PublishAsync(new DistributedEventSent + { + Source = DistributedEventSource.Direct, + EventName = EventNameAttribute.GetNameOrDefault(eventType), + EventData = eventData + }, onUnitOfWorkComplete); } - await _localEventBus.PublishAsync(new DistributedEventSent - { - Source = DistributedEventSource.Direct, - EventName = EventNameAttribute.GetNameOrDefault(eventType), - EventData = eventData - }, onUnitOfWorkComplete); - - await _localEventBus.PublishAsync(new DistributedEventReceived + if (eventType != typeof(DistributedEventReceived)) { - Source = DistributedEventSource.Direct, - EventName = EventNameAttribute.GetNameOrDefault(eventType), - EventData = eventData - }, onUnitOfWorkComplete); + await _localEventBus.PublishAsync(new DistributedEventReceived + { + Source = DistributedEventSource.Direct, + EventName = EventNameAttribute.GetNameOrDefault(eventType), + EventData = eventData + }, onUnitOfWorkComplete); + } } }