Browse Source

Add `PostConfigureAbpRabbitMqEventBusOptions`.

pull/23016/head
maliming 1 year ago
parent
commit
a81f838e83
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 55
      framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpEventBusRabbitMqModule.cs
  2. 54
      framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/PostConfigureAbpRabbitMqEventBusOptions.cs

55
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<string> 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<string> boolQueueArguments = ["x-single-active-consumer"];
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
Configure<AbpRabbitMqEventBusOptions>(configuration.GetSection("RabbitMQ:EventBus"));
context.Services.Configure<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
)
{
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<IPostConfigureOptions<AbpRabbitMqEventBusOptions>, PostConfigureAbpRabbitMqEventBusOptions>());
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

54
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<AbpRabbitMqEventBusOptions>
{
private readonly HashSet<string> _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<string> _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
}
}
}
}
Loading…
Cancel
Save