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] 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)