From 10fa66936f777962ec11d472f142a6b0583d073a Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 22 Jan 2019 13:29:27 +0300 Subject: [PATCH] Rename RabbitMqDistributedEventBusOptions to RabbitMqEventBusOptions. --- .../RabbitMq/AbpEventBusRabbitMqModule.cs | 9 +++++++- .../RabbitMq/RabbitMqDistributedEventBus.cs | 21 +++++++++---------- ...sOptions.cs => RabbitMqEventBusOptions.cs} | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) rename framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/{RabbitMqDistributedEventBusOptions.cs => RabbitMqEventBusOptions.cs} (80%) diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/AbpEventBusRabbitMqModule.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/AbpEventBusRabbitMqModule.cs index c07c2c5127..aa191cf946 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/AbpEventBusRabbitMqModule.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/AbpEventBusRabbitMqModule.cs @@ -1,6 +1,8 @@ -using Volo.Abp.Modularity; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; using Volo.Abp.RabbitMQ; +//TODO: Rename Volo.Abp.EventBus.Distributed.RabbitMq namespace to Volo.Abp.EventBus.RabbitMq namespace Volo.Abp.EventBus.Distributed.RabbitMq { [DependsOn( @@ -8,6 +10,11 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq typeof(AbpRabbitMqModule))] public class AbpEventBusRabbitMqModule : AbpModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(configuration.GetSection("RabbitMqEventBus")); + } } } diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs index 223ea4225f..749113f22e 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq [ExposeServices(typeof(IDistributedEventBus), typeof(RabbitMqDistributedEventBus))] public class RabbitMqDistributedEventBus : EventBusBase, IDistributedEventBus, ISingletonDependency { - protected RabbitMqDistributedEventBusOptions RabbitMqDistributedEventBusOptions { get; } + protected RabbitMqEventBusOptions RabbitMqEventBusOptions { get; } protected DistributedEventBusOptions DistributedEventBusOptions { get; } protected IConnectionPool ConnectionPool { get; } protected IRabbitMqSerializer Serializer { get; } @@ -32,7 +32,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq protected IRabbitMqMessageConsumer Consumer { get; } public RabbitMqDistributedEventBus( - IOptions options, + IOptions options, IConnectionPool connectionPool, IRabbitMqSerializer serializer, IHybridServiceScopeFactory serviceScopeFactory, @@ -44,24 +44,24 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq Serializer = serializer; MessageConsumerFactory = messageConsumerFactory; DistributedEventBusOptions = distributedEventBusOptions.Value; - RabbitMqDistributedEventBusOptions = options.Value; + RabbitMqEventBusOptions = options.Value; HandlerFactories = new ConcurrentDictionary>(); EventTypes = new ConcurrentDictionary(); Consumer = MessageConsumerFactory.Create( new ExchangeDeclareConfiguration( - RabbitMqDistributedEventBusOptions.ExchangeName, + RabbitMqEventBusOptions.ExchangeName, type: "direct", durable: true ), new QueueDeclareConfiguration( - RabbitMqDistributedEventBusOptions.ClientName, + RabbitMqEventBusOptions.ClientName, durable: true, exclusive: false, autoDelete: false ), - RabbitMqDistributedEventBusOptions.ConnectionName + RabbitMqEventBusOptions.ConnectionName ); Consumer.OnMessageReceived(ProcessEventAsync); @@ -96,8 +96,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq if (handlerFactories.Count == 1) //TODO: Multi-threading! { - var eventName = EventNameAttribute.GetNameOrDefault(eventType); - Consumer.BindAsync(eventName); + Consumer.BindAsync(EventNameAttribute.GetNameOrDefault(eventType)); } return new EventHandlerFactoryUnregistrar(this, eventType, factory); @@ -162,10 +161,10 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq var eventName = EventNameAttribute.GetNameOrDefault(eventType); var body = Serializer.Serialize(eventData); - using (var channel = ConnectionPool.Get(RabbitMqDistributedEventBusOptions.ConnectionName).CreateModel()) + using (var channel = ConnectionPool.Get(RabbitMqEventBusOptions.ConnectionName).CreateModel()) { channel.ExchangeDeclare( - RabbitMqDistributedEventBusOptions.ExchangeName, + RabbitMqEventBusOptions.ExchangeName, "direct", durable: true ); @@ -174,7 +173,7 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq properties.DeliveryMode = RabbitMqConsts.DeliveryModes.Persistent; channel.BasicPublish( - exchange: RabbitMqDistributedEventBusOptions.ExchangeName, + exchange: RabbitMqEventBusOptions.ExchangeName, routingKey: eventName, mandatory: true, basicProperties: properties, diff --git a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqEventBusOptions.cs similarity index 80% rename from framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBusOptions.cs rename to framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqEventBusOptions.cs index dbcf916b0c..7b7b95dc84 100644 --- a/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqEventBusOptions.cs @@ -1,6 +1,6 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq { - public class RabbitMqDistributedEventBusOptions + public class RabbitMqEventBusOptions { public string ConnectionName { get; set; }