Browse Source
Merge pull request #18294 from abpframework/liangshiwei/rabbitmq
Add more Arguments to AbpRabbitMqEventBusOptions
pull/18308/head
maliming
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
37 additions and
8 deletions
docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md
docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md
framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/AbpRabbitMqEventBusOptions.cs
framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ExchangeDeclareConfiguration.cs
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/QueueDeclareConfiguration.cs
@ -152,4 +152,14 @@ Configure<AbpRabbitMqEventBusOptions>(options =>
});
});
````
````
**Example: Configure the queue and exchange optional arguments**
```csharp
Configure< AbpRabbitMqEventBusOptions > (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.
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.
@ -152,4 +152,14 @@ Configure<AbpRabbitMqEventBusOptions>(options =>
});
});
````
````
**示例:配置队列和交换机的额外参数**
```csharp
Configure< AbpRabbitMqEventBusOptions > (options =>
{
options.ExchangeArguments["x-delayed-type"] = "direct";
options.QueueArguments["x-message-ttl"] = 60000;
});
```
使用这些选项类可以与 `appsettings.json` 组合在一起. 在代码中配置选项属性会覆盖配置文件中的值.
使用这些选项类可以与 `appsettings.json` 组合在一起. 在代码中配置选项属性会覆盖配置文件中的值.
@ -1,4 +1,5 @@
using Volo.Abp.RabbitMQ ;
using System.Collections.Generic ;
using Volo.Abp.RabbitMQ ;
namespace Volo.Abp.EventBus.RabbitMq ;
namespace Volo.Abp.EventBus.RabbitMq ;
@ -13,9 +14,13 @@ public class AbpRabbitMqEventBusOptions
public string ExchangeName { get ; set ; } = default ! ;
public string ExchangeName { get ; set ; } = default ! ;
public string? ExchangeType { get ; set ; }
public string? ExchangeType { get ; set ; }
public ushort? PrefetchCount { get ; set ; }
public ushort? PrefetchCount { get ; set ; }
public IDictionary < string , object > QueueArguments { get ; set ; } = new Dictionary < string , object > ( ) ;
public IDictionary < string , object > ExchangeArguments { get ; set ; } = new Dictionary < string , object > ( ) ;
public string GetExchangeTypeOrDefault ( )
public string GetExchangeTypeOrDefault ( )
{
{
return string . IsNullOrEmpty ( ExchangeType )
return string . IsNullOrEmpty ( ExchangeType )
@ -79,14 +79,16 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe
new ExchangeDeclareConfiguration (
new ExchangeDeclareConfiguration (
AbpRabbitMqEventBusOptions . ExchangeName ,
AbpRabbitMqEventBusOptions . ExchangeName ,
type : AbpRabbitMqEventBusOptions . GetExchangeTypeOrDefault ( ) ,
type : AbpRabbitMqEventBusOptions . GetExchangeTypeOrDefault ( ) ,
durable : true
durable : true ,
arguments : AbpRabbitMqEventBusOptions . ExchangeArguments
) ,
) ,
new QueueDeclareConfiguration (
new QueueDeclareConfiguration (
AbpRabbitMqEventBusOptions . ClientName ,
AbpRabbitMqEventBusOptions . ClientName ,
durable : true ,
durable : true ,
exclusive : false ,
exclusive : false ,
autoDelete : false ,
autoDelete : false ,
prefetchCount : AbpRabbitMqEventBusOptions . PrefetchCount
prefetchCount : AbpRabbitMqEventBusOptions . PrefetchCount ,
arguments : AbpRabbitMqEventBusOptions . QueueArguments
) ,
) ,
AbpRabbitMqEventBusOptions . ConnectionName
AbpRabbitMqEventBusOptions . ConnectionName
) ;
) ;
@ -18,12 +18,13 @@ public class ExchangeDeclareConfiguration
string exchangeName ,
string exchangeName ,
string type ,
string type ,
bool durable = false ,
bool durable = false ,
bool autoDelete = false )
bool autoDelete = false ,
IDictionary < string , object > ? arguments = null )
{
{
ExchangeName = exchangeName ;
ExchangeName = exchangeName ;
Type = type ;
Type = type ;
Durable = durable ;
Durable = durable ;
AutoDelete = autoDelete ;
AutoDelete = autoDelete ;
Arguments = new Dictionary < string , object > ( ) ;
Arguments = arguments ? ? new Dictionary < string , object > ( ) ;
}
}
}
}
@ -23,13 +23,14 @@ public class QueueDeclareConfiguration
bool durable = true ,
bool durable = true ,
bool exclusive = false ,
bool exclusive = false ,
bool autoDelete = false ,
bool autoDelete = false ,
ushort? prefetchCount = null )
ushort? prefetchCount = null ,
IDictionary < string , object > ? arguments = null )
{
{
QueueName = queueName ;
QueueName = queueName ;
Durable = durable ;
Durable = durable ;
Exclusive = exclusive ;
Exclusive = exclusive ;
AutoDelete = autoDelete ;
AutoDelete = autoDelete ;
Arguments = new Dictionary < string , object > ( ) ;
Arguments = arguments ? ? new Dictionary < string , object > ( ) ;
PrefetchCount = prefetchCount ;
PrefetchCount = prefetchCount ;
}
}