Skip to content

Commit

Permalink
Added control for queue options in RabbitMQ transport (#1585)
Browse files Browse the repository at this point in the history
* updated documentation
  • Loading branch information
apatozi committed Sep 20, 2024
1 parent f304b1b commit 83c0dbf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/content/user-guide/en/transport/rabbitmq.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ VirtualHost | Broker virtual host | string | /
Port | Port | int | -1
ExchangeName | Default exchange name | string | cap.default.topic
QueueArguments | Extra queue `x-arguments` | QueueArgumentsOptions | N/A
QueueOptions | Change Options for created queue | QueueRabbitOptions | { Durable=true, Exclusive=false, AutoDelete=false }
ConnectionFactoryOptions | RabbitMQClient native connection options | ConnectionFactory | N/A
CustomHeadersBuilder | Custom subscribe headers | See the blow | N/A
PublishConfirms | Enable [publish confirms](https://www.rabbitmq.com/confirms.html#publisher-confirms) | bool | false
Expand Down
1 change: 1 addition & 0 deletions docs/content/user-guide/zh/transport/rabbitmq.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ VirtualHost | 虚拟主机 | string | /
Port | 端口号 | int | -1
ExchangeName | CAP默认Exchange名称 | string | cap.default.topic
QueueArguments | 队列额外参数 x-arguments | QueueArgumentsOptions | N/A
QueueOptions | 更改已创建队列的选项 | QueueRabbitOptions | { Durable=true, Exclusive=false, AutoDelete=false }
ConnectionFactoryOptions | RabbitMQClient原生参数 | ConnectionFactory | N/A
CustomHeadersBuilder | 订阅者自定义头信息 | 见下文 | N/A
PublishConfirms | 是否启用[发布确认](https://www.rabbitmq.com/confirms.html#publisher-confirms) | bool | false
Expand Down
17 changes: 16 additions & 1 deletion src/DotNetCore.CAP.RabbitMQ/CAP.RabbiMQOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public class RabbitMQOptions
/// </summary>
public QueueArgumentsOptions QueueArguments { get; set; } = new();


/// <summary>
/// Optional queue arguments, also known as "x-arguments" because of their field name in the AMQP 0-9-1 protocol,
/// is a map (dictionary) of arbitrary key/value pairs that can be provided by clients when a queue is declared.
/// </summary>
public QueueRabbitOptions QueueOptions { get; set; } = new();

/// <summary>
/// If you need to get additional native delivery args, you can use this function to write into <see cref="CapHeader" />.
/// </summary>
Expand Down Expand Up @@ -155,4 +162,12 @@ public BasicQos(ushort prefetchCount, bool global = false)
/// </summary>
public bool Global { get; }
}
}

public class QueueRabbitOptions
{
public bool Durable { get; set; } = true;
public bool Exclusive { get; set; } = false;
public bool AutoDelete { get; set; } = false;
}
}

2 changes: 1 addition & 1 deletion src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void Connect()

try
{
_channel.QueueDeclare(_queueName, true, false, false, arguments);
_channel.QueueDeclare(_queueName, _rabbitMQOptions.QueueOptions.Durable, _rabbitMQOptions.QueueOptions.Exclusive, _rabbitMQOptions.QueueOptions.AutoDelete, arguments);
}
catch (TimeoutException ex)
{
Expand Down

0 comments on commit 83c0dbf

Please sign in to comment.