From f1cbcb16c7e7fa5f4b21603d981fdbf9619dc223 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 18 Mar 2022 11:55:14 +0800 Subject: [PATCH] Update RabbitMqDistributedEventBus --- .../RabbitMq/RabbitMqDistributedEventBus.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs index b9210a6eb8..73ca0cbb61 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs @@ -86,8 +86,6 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe Consumer.OnMessageReceived(ProcessEventAsync); SubscribeHandlers(AbpDistributedEventBusOptions.Handlers); - - } private async Task ProcessEventAsync(IModel channel, BasicDeliverEventArgs ea) @@ -313,12 +311,20 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe { return; } - - channel.ExchangeDeclare( - AbpRabbitMqEventBusOptions.ExchangeName, - "direct", - durable: true - ); + + try + { + channel.ExchangeDeclarePassive(AbpRabbitMqEventBusOptions.ExchangeName); + } + catch (Exception) + { + channel.ExchangeDeclare( + AbpRabbitMqEventBusOptions.ExchangeName, + "direct", + durable: true + ); + } + _exchangeCreated = true; } private void SetEventMessageHeaders(IBasicProperties properties, Dictionary headersArguments)