From e4b5ed052766105a0089a4cb7e420195c88f94ce Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 10 Jan 2022 15:51:29 +0800 Subject: [PATCH] Fix Azure event bus publishing issue --- .../EventBus/Azure/AzureDistributedEventBus.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs index f809159346..7d6900be60 100644 --- a/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Azure/Volo/Abp/EventBus/Azure/AzureDistributedEventBus.cs @@ -87,7 +87,7 @@ namespace Volo.Abp.EventBus.Azure public override async Task PublishFromOutboxAsync(OutgoingEventInfo outgoingEvent, OutboxConfig outboxConfig) { - await PublishAsync(outgoingEvent.EventName, outgoingEvent.EventData); + await PublishAsync(outgoingEvent.EventName, outgoingEvent.EventData, outgoingEvent.Id); } public override async Task ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig) @@ -188,15 +188,28 @@ namespace Volo.Abp.EventBus.Azure unitOfWork.AddOrReplaceDistributedEvent(eventRecord); } - protected virtual async Task PublishAsync(string eventName, object eventData) + protected virtual Task PublishAsync(string eventName, object eventData) { var body = _serializer.Serialize(eventData); + return PublishAsync(eventName, body, null); + } + + protected virtual async Task PublishAsync( + string eventName, + byte[] body, + Guid? eventId) + { var message = new ServiceBusMessage(body) { Subject = eventName }; + if (message.MessageId.IsNullOrWhiteSpace()) + { + message.MessageId = (eventId ?? GuidGenerator.Create()).ToString("N"); + } + var publisher = await _publisherPool.GetAsync( _options.TopicName, _options.ConnectionName);