From 343e409508882082ef16d15bc6d88623cd0ae88a Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Thu, 3 Aug 2017 10:08:55 +0800 Subject: [PATCH] set exchange and queue with durable. --- src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs | 2 +- src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs b/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs index 17b0ee2..27b777b 100644 --- a/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs +++ b/src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs @@ -43,7 +43,7 @@ namespace DotNetCore.CAP.RabbitMQ { var body = Encoding.UTF8.GetBytes(content); - channel.ExchangeDeclare(_rabbitMQOptions.TopicExchangeName, RabbitMQOptions.ExchangeType); + channel.ExchangeDeclare(_rabbitMQOptions.TopicExchangeName, RabbitMQOptions.ExchangeType, durable: true); channel.BasicPublish(exchange: _rabbitMQOptions.TopicExchangeName, routingKey: keyName, basicProperties: null, diff --git a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs index ba25b7b..8bf9ab6 100644 --- a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs +++ b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs @@ -48,12 +48,18 @@ namespace DotNetCore.CAP.RabbitMQ _connection = _connectionFactory.CreateConnection(); _channel = _connection.CreateModel(); - _channel.ExchangeDeclare(exchange: _exchageName, type: RabbitMQOptions.ExchangeType); + + _channel.ExchangeDeclare( + exchange: _exchageName, + type: RabbitMQOptions.ExchangeType, + durable: true); + + var arguments = new Dictionary { { "x-message-ttl", (int)_rabbitMQOptions.XMessageTTL.TotalMilliseconds } }; _channel.QueueDeclare(_queueName, durable: true, exclusive: false, autoDelete: false, - arguments: new Dictionary { { "message-ttl", _rabbitMQOptions.XMessageTTL.TotalMilliseconds } }); + arguments: arguments); } public void Subscribe(IEnumerable topics)