From b030933ff56cb9a1b4b6d76366fbfc45e7bf7d43 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 29 Nov 2023 15:59:38 +0800 Subject: [PATCH 1/2] Add more Arguments to AbpRabbitMqEventBusOptions --- .../Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs | 9 +++++++-- .../Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs | 6 ++++-- .../Volo/Abp/RabbitMQ/ExchangeDeclareConfiguration.cs | 5 +++-- .../Volo/Abp/RabbitMQ/QueueDeclareConfiguration.cs | 5 +++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs index a017d53d5d..130f5b38e2 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs @@ -1,4 +1,5 @@ -using Volo.Abp.RabbitMQ; +using System.Collections.Generic; +using Volo.Abp.RabbitMQ; namespace Volo.Abp.EventBus.RabbitMq; @@ -13,9 +14,13 @@ public class AbpRabbitMqEventBusOptions public string ExchangeName { get; set; } = default!; public string? ExchangeType { get; set; } - + public ushort? PrefetchCount { get; set; } + public IDictionary QueueArguments { get; set; } = new Dictionary(); + + public IDictionary ExchangeArguments { get; set; } = new Dictionary(); + public string GetExchangeTypeOrDefault() { return string.IsNullOrEmpty(ExchangeType) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs index 2c0bb7aab5..dbaedf7779 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs @@ -79,14 +79,16 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe new ExchangeDeclareConfiguration( AbpRabbitMqEventBusOptions.ExchangeName, type: AbpRabbitMqEventBusOptions.GetExchangeTypeOrDefault(), - durable: true + durable: true, + arguments: AbpRabbitMqEventBusOptions.ExchangeArguments ), new QueueDeclareConfiguration( AbpRabbitMqEventBusOptions.ClientName, durable: true, exclusive: false, autoDelete: false, - prefetchCount: AbpRabbitMqEventBusOptions.PrefetchCount + prefetchCount: AbpRabbitMqEventBusOptions.PrefetchCount, + arguments: AbpRabbitMqEventBusOptions.QueueArguments ), AbpRabbitMqEventBusOptions.ConnectionName ); diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ExchangeDeclareConfiguration.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ExchangeDeclareConfiguration.cs index ca904cc94f..5c239893c7 100644 --- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ExchangeDeclareConfiguration.cs +++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ExchangeDeclareConfiguration.cs @@ -18,12 +18,13 @@ public class ExchangeDeclareConfiguration string exchangeName, string type, bool durable = false, - bool autoDelete = false) + bool autoDelete = false, + IDictionary? arguments = null) { ExchangeName = exchangeName; Type = type; Durable = durable; AutoDelete = autoDelete; - Arguments = new Dictionary(); + Arguments = arguments?? new Dictionary(); } } diff --git a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/QueueDeclareConfiguration.cs b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/QueueDeclareConfiguration.cs index 4b03c788c6..eb59ec3058 100644 --- a/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/QueueDeclareConfiguration.cs +++ b/framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/QueueDeclareConfiguration.cs @@ -23,13 +23,14 @@ public class QueueDeclareConfiguration bool durable = true, bool exclusive = false, bool autoDelete = false, - ushort? prefetchCount = null) + ushort? prefetchCount = null, + IDictionary? arguments = null) { QueueName = queueName; Durable = durable; Exclusive = exclusive; AutoDelete = autoDelete; - Arguments = new Dictionary(); + Arguments = arguments?? new Dictionary(); PrefetchCount = prefetchCount; } From 3e73dbf4305c1d4d33f9bc9bef40bd52a9643fdf Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 29 Nov 2023 16:14:23 +0800 Subject: [PATCH 2/2] Update document --- docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md | 10 ++++++++++ .../Distributed-Event-Bus-RabbitMQ-Integration.md | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md b/docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md index 4823cbaae9..ef174f92b0 100644 --- a/docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md +++ b/docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md @@ -152,4 +152,14 @@ Configure(options => }); ```` +**Example: Configure the queue and exchange optional arguments** + +```csharp +Configure(options => +{ + options.ExchangeArguments["x-delayed-type"] = "direct"; + options.QueueArguments["x-message-ttl"] = 60000; +}); +``` + Using these options classes can be combined with the `appsettings.json` way. Configuring an option property in the code overrides the value in the configuration file. diff --git a/docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md b/docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md index f45d4d90bf..57530e1d6f 100644 --- a/docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md +++ b/docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md @@ -152,4 +152,14 @@ Configure(options => }); ```` +**示例:配置队列和交换机的额外参数** + +```csharp +Configure(options => +{ + options.ExchangeArguments["x-delayed-type"] = "direct"; + options.QueueArguments["x-message-ttl"] = 60000; +}); +``` + 使用这些选项类可以与 `appsettings.json` 组合在一起. 在代码中配置选项属性会覆盖配置文件中的值.