From 36f5dd4a651f6931916af3e6e9303280132d8958 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 22 Nov 2024 11:14:31 +0800 Subject: [PATCH 1/2] Skip to set `CorrelationId ` if current value is `null`. Resolve #21419 --- .../Abp/EventBus/Distributed/DistributedEventBusBase.cs | 5 ++++- .../Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs | 6 +++++- .../Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs index 72a20748c68..c3168182312 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs @@ -132,7 +132,10 @@ protected virtual async Task AddToOutboxAsync(Type eventType, object event Serialize(eventData), Clock.Now ); - outgoingEventInfo.SetCorrelationId(CorrelationIdProvider.Get()!); + if (CorrelationIdProvider.Get() != null) + { + outgoingEventInfo.SetCorrelationId(CorrelationIdProvider.Get()!); + } await eventOutbox.EnqueueAsync(outgoingEventInfo); return true; } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs index a4306050a4d..e2562d28cd1 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs @@ -309,7 +309,11 @@ protected virtual void AddHeaders( } //CorrelationId - requestMessage.Headers.Add(AbpCorrelationIdOptions.Value.HttpHeaderName, CorrelationIdProvider.Get()); + var correlationId = CorrelationIdProvider.Get(); + if (correlationId != null) + { + requestMessage.Headers.Add(AbpCorrelationIdOptions.Value.HttpHeaderName, correlationId); + } //TenantId if (CurrentTenant.Id.HasValue) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs index 10089c52cd0..e54e24ced0e 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs @@ -126,7 +126,11 @@ protected virtual async Task GetApiDescriptionFr protected virtual void AddHeaders(HttpRequestMessage requestMessage) { //CorrelationId - requestMessage.Headers.Add(AbpCorrelationIdOptions.HttpHeaderName, CorrelationIdProvider.Get()); + var correlationId = CorrelationIdProvider.Get(); + if (correlationId != null) + { + requestMessage.Headers.Add(AbpCorrelationIdOptions.HttpHeaderName, correlationId); + } //TenantId if (CurrentTenant.Id.HasValue) From d49665ca270b921aac400caeac7313ebb6c228a3 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 22 Nov 2024 11:16:46 +0800 Subject: [PATCH 2/2] Update DistributedEventBusBase.cs --- .../Abp/EventBus/Distributed/DistributedEventBusBase.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs index c3168182312..96a11f928ec 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs @@ -132,10 +132,13 @@ protected virtual async Task AddToOutboxAsync(Type eventType, object event Serialize(eventData), Clock.Now ); - if (CorrelationIdProvider.Get() != null) + + var correlationId = CorrelationIdProvider.Get(); + if (correlationId != null) { - outgoingEventInfo.SetCorrelationId(CorrelationIdProvider.Get()!); + outgoingEventInfo.SetCorrelationId(correlationId); } + await eventOutbox.EnqueueAsync(outgoingEventInfo); return true; }