diff --git a/docs/content/user-guide/en/transport/rabbitmq.md b/docs/content/user-guide/en/transport/rabbitmq.md index 7ac13c14..bfd1285e 100644 --- a/docs/content/user-guide/en/transport/rabbitmq.md +++ b/docs/content/user-guide/en/transport/rabbitmq.md @@ -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 diff --git a/docs/content/user-guide/zh/transport/rabbitmq.md b/docs/content/user-guide/zh/transport/rabbitmq.md index 111fb8a3..678d879c 100644 --- a/docs/content/user-guide/zh/transport/rabbitmq.md +++ b/docs/content/user-guide/zh/transport/rabbitmq.md @@ -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 diff --git a/src/DotNetCore.CAP.RabbitMQ/CAP.RabbiMQOptions.cs b/src/DotNetCore.CAP.RabbitMQ/CAP.RabbiMQOptions.cs index 06fd7d6a..44cae5b9 100644 --- a/src/DotNetCore.CAP.RabbitMQ/CAP.RabbiMQOptions.cs +++ b/src/DotNetCore.CAP.RabbitMQ/CAP.RabbiMQOptions.cs @@ -80,6 +80,13 @@ public class RabbitMQOptions /// public QueueArgumentsOptions QueueArguments { get; set; } = new(); + + /// + /// 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. + /// + public QueueRabbitOptions QueueOptions { get; set; } = new(); + /// /// If you need to get additional native delivery args, you can use this function to write into . /// @@ -155,4 +162,12 @@ public BasicQos(ushort prefetchCount, bool global = false) /// public bool Global { get; } } -} \ No newline at end of file + + public class QueueRabbitOptions + { + public bool Durable { get; set; } = true; + public bool Exclusive { get; set; } = false; + public bool AutoDelete { get; set; } = false; + } +} + diff --git a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs index b1fc8342..42f4665a 100644 --- a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs +++ b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs @@ -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) {