From 0c4e460d393905837eaa3c7933901f228ff9c02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herbst?= Date: Fri, 6 Jun 2025 23:25:49 +0200 Subject: [PATCH 1/3] fix: ensure RabbitMQ QueueArguments from appsettings are parsed into correct types Issue: #23015 --- .../RabbitMq/AbpEventBusRabbitMqModule.cs | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs index 92399b43b0..e09225a83c 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; using Volo.Abp.RabbitMQ; @@ -9,11 +10,59 @@ namespace Volo.Abp.EventBus.RabbitMq; typeof(AbpRabbitMqModule))] public class AbpEventBusRabbitMqModule : AbpModule { + protected HashSet uint64QueueArguments = + [ + "x-delivery-limit", + "x-expires", + "x-message-ttl", + "x-max-length", + "x-max-length-bytes", + "x-quorum-initial-group-size", + "x-quorum-target-group-size", + "x-stream-filter-size-bytes", + "x-stream-max-segment-size-bytes", + ]; + protected HashSet boolQueueArguments = ["x-single-active-consumer"]; + public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); Configure(configuration.GetSection("RabbitMQ:EventBus")); + + context.Services.Configure(options => + { + ParseBoolQueueArguments(options); + ParseIntegerQueueArguments(options); + }); + } + + protected virtual void ParseBoolQueueArguments(AbpRabbitMqEventBusOptions options) + { + foreach (var argument in boolQueueArguments) + { + if ( + options.QueueArguments.TryGetValue(argument, out var value) + && value is string stringValue + ) + { + options.QueueArguments[argument] = bool.Parse(stringValue); + } + } + } + + protected virtual void ParseIntegerQueueArguments(AbpRabbitMqEventBusOptions options) + { + foreach (var argument in uint64QueueArguments) + { + if ( + options.QueueArguments.TryGetValue(argument, out var value) + && value is string stringValue + ) + { + options.QueueArguments[argument] = int.Parse(stringValue); + } + } } public override void OnApplicationInitialization(ApplicationInitializationContext context) From a81f838e837e7d561b7b194c8714eae4302f8636 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 9 Jun 2025 11:16:21 +0800 Subject: [PATCH 2/3] Add `PostConfigureAbpRabbitMqEventBusOptions`. --- .../RabbitMq/AbpEventBusRabbitMqModule.cs | 55 ++----------------- ...PostConfigureAbpRabbitMqEventBusOptions.cs | 54 ++++++++++++++++++ 2 files changed, 58 insertions(+), 51 deletions(-) create mode 100644 framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs index e09225a83c..5d811a76cc 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs @@ -1,5 +1,6 @@ -using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Options; using Volo.Abp.Modularity; using Volo.Abp.RabbitMQ; @@ -10,59 +11,11 @@ namespace Volo.Abp.EventBus.RabbitMq; typeof(AbpRabbitMqModule))] public class AbpEventBusRabbitMqModule : AbpModule { - protected HashSet uint64QueueArguments = - [ - "x-delivery-limit", - "x-expires", - "x-message-ttl", - "x-max-length", - "x-max-length-bytes", - "x-quorum-initial-group-size", - "x-quorum-target-group-size", - "x-stream-filter-size-bytes", - "x-stream-max-segment-size-bytes", - ]; - protected HashSet boolQueueArguments = ["x-single-active-consumer"]; - public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - Configure(configuration.GetSection("RabbitMQ:EventBus")); - - context.Services.Configure(options => - { - ParseBoolQueueArguments(options); - ParseIntegerQueueArguments(options); - }); - } - - protected virtual void ParseBoolQueueArguments(AbpRabbitMqEventBusOptions options) - { - foreach (var argument in boolQueueArguments) - { - if ( - options.QueueArguments.TryGetValue(argument, out var value) - && value is string stringValue - ) - { - options.QueueArguments[argument] = bool.Parse(stringValue); - } - } - } - - protected virtual void ParseIntegerQueueArguments(AbpRabbitMqEventBusOptions options) - { - foreach (var argument in uint64QueueArguments) - { - if ( - options.QueueArguments.TryGetValue(argument, out var value) - && value is string stringValue - ) - { - options.QueueArguments[argument] = int.Parse(stringValue); - } - } + context.Services.TryAddEnumerable(ServiceDescriptor.Singleton, PostConfigureAbpRabbitMqEventBusOptions>()); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs new file mode 100644 index 0000000000..fd64da926d --- /dev/null +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using Microsoft.Extensions.Options; + +namespace Volo.Abp.EventBus.RabbitMq; + +public class PostConfigureAbpRabbitMqEventBusOptions : IPostConfigureOptions +{ + private readonly HashSet _uint64QueueArguments = + [ + "x-delivery-limit", + "x-expires", + "x-message-ttl", + "x-max-length", + "x-max-length-bytes", + "x-quorum-initial-group-size", + "x-quorum-target-group-size", + "x-stream-filter-size-bytes", + "x-stream-max-segment-size-bytes", + ]; + + private readonly HashSet _boolQueueArguments = + [ + "x-single-active-consumer" + ]; + + public virtual void PostConfigure(string? name, AbpRabbitMqEventBusOptions options) + { + ParseBoolQueueArguments(options); + ParseIntegerQueueArguments(options); + } + + protected virtual void ParseBoolQueueArguments(AbpRabbitMqEventBusOptions options) + { + foreach (var argument in _boolQueueArguments) + { + if (options.QueueArguments.TryGetValue(argument, out var value) && value is string stringValue && bool.TryParse(stringValue, out var boolValue)) + { + options.QueueArguments[argument] = boolValue; + } + } + } + + protected virtual void ParseIntegerQueueArguments(AbpRabbitMqEventBusOptions options) + { + foreach (var argument in _uint64QueueArguments) + { + if (options.QueueArguments.TryGetValue(argument, out var value) && value is string stringValue && int.TryParse(stringValue, out var intValue)) + { + options.QueueArguments[argument] = intValue + } + } + } + +} From c5d99180a444f5000f7149cb9abc4583a762f2fd Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 9 Jun 2025 11:24:11 +0800 Subject: [PATCH 3/3] Update PostConfigureAbpRabbitMqEventBusOptions.cs --- .../RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs index fd64da926d..f4e69c46c6 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs @@ -46,7 +46,7 @@ public class PostConfigureAbpRabbitMqEventBusOptions : IPostConfigureOptions