Skip to content

Commit

Permalink
Merge pull request #18294 from abpframework/liangshiwei/rabbitmq
Browse files Browse the repository at this point in the history
Add more Arguments to AbpRabbitMqEventBusOptions
  • Loading branch information
maliming authored Nov 29, 2023
2 parents 7c7f71a + 3e73dbf commit 66ce721
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/en/Distributed-Event-Bus-RabbitMQ-Integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 10 additions & 0 deletions docs/zh-Hans/Distributed-Event-Bus-RabbitMQ-Integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 组合在一起. 在代码中配置选项属性会覆盖配置文件中的值.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Volo.Abp.RabbitMQ;
using System.Collections.Generic;
using Volo.Abp.RabbitMQ;

namespace Volo.Abp.EventBus.RabbitMq;

Expand All @@ -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<string, object> QueueArguments { get; set; } = new Dictionary<string, object>();

public IDictionary<string, object> ExchangeArguments { get; set; } = new Dictionary<string, object>();

public string GetExchangeTypeOrDefault()
{
return string.IsNullOrEmpty(ExchangeType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ public void Initialize()
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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public ExchangeDeclareConfiguration(
string exchangeName,
string type,
bool durable = false,
bool autoDelete = false)
bool autoDelete = false,
IDictionary<string, object>? arguments = null)
{
ExchangeName = exchangeName;
Type = type;
Durable = durable;
AutoDelete = autoDelete;
Arguments = new Dictionary<string, object>();
Arguments = arguments?? new Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public QueueDeclareConfiguration(
bool durable = true,
bool exclusive = false,
bool autoDelete = false,
ushort? prefetchCount = null)
ushort? prefetchCount = null,
IDictionary<string, object>? arguments = null)
{
QueueName = queueName;
Durable = durable;
Exclusive = exclusive;
AutoDelete = autoDelete;
Arguments = new Dictionary<string, object>();
Arguments = arguments?? new Dictionary<string, object>();
PrefetchCount = prefetchCount;
}

Expand Down

0 comments on commit 66ce721

Please sign in to comment.