From 1016a1662d2cb3f669538eeea9817fea083be61d Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Mon, 12 Nov 2018 16:15:39 +0300 Subject: [PATCH] #33 Created IDistributedEventBus --- .../RabbitMq/RabbitMqDistributedEventBus.cs | 30 +++++++++++ .../Distributed/IDistributedEventBus.cs | 52 +++++++++++++++++++ .../Distributed/IDistributedEventHandler.cs | 13 +++++ .../Distributed/LocalDistributedEventBus.cs | 30 +++++++++++ 4 files changed, 125 insertions(+) create mode 100644 framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventHandler.cs diff --git a/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs index 68131b3ab8..772948a706 100644 --- a/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus.Distributed.RabbitMQ/Volo/Abp/EventBus/Distributed/RabbitMq/RabbitMqDistributedEventBus.cs @@ -6,6 +6,36 @@ namespace Volo.Abp.EventBus.Distributed.RabbitMq { public class RabbitMqDistributedEventBus : IDistributedEventBus, ITransientDependency { + public IDisposable Subscribe(Func action) where TEvent : class + { + throw new NotImplementedException(); + } + + public IDisposable Subscribe(IEventHandler handler) where TEvent : class + { + throw new NotImplementedException(); + } + + public IDisposable Subscribe() where TEvent : class where THandler : IEventHandler, new() + { + throw new NotImplementedException(); + } + + public IDisposable Subscribe(Type eventType, IEventHandler handler) + { + throw new NotImplementedException(); + } + + public IDisposable Subscribe(IEventHandlerFactory factory) where TEvent : class + { + throw new NotImplementedException(); + } + + public IDisposable Subscribe(Type eventType, IEventHandlerFactory factory) + { + throw new NotImplementedException(); + } + public Task PublishAsync(TEvent eventData) where TEvent : class { diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventBus.cs index 49f50b24c5..26bbe9cb1c 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventBus.cs @@ -5,6 +5,58 @@ namespace Volo.Abp.EventBus.Distributed { public interface IDistributedEventBus { + /// + /// Subscribes to an event. + /// Given action is called for all event occurrences. + /// + /// Action to handle events + /// Event type + IDisposable Subscribe(Func action) + where TEvent : class; + + /// + /// Subscribes to an event. + /// Same (given) instance of the handler is used for all event occurrences. + /// + /// Event type + /// Object to handle the event + IDisposable Subscribe(IEventHandler handler) + where TEvent : class; + + /// + /// Subscribes to an event. + /// A new instance of object is created for every event occurrence. + /// + /// Event type + /// Type of the event handler + IDisposable Subscribe() + where TEvent : class + where THandler : IEventHandler, new(); + + /// + /// Subscribes to an event. + /// Same (given) instance of the handler is used for all event occurrences. + /// + /// Event type + /// Object to handle the event + IDisposable Subscribe(Type eventType, IEventHandler handler); + + /// + /// Subscribes to an event. + /// Given factory is used to create/release handlers + /// + /// Event type + /// A factory to create/release handlers + IDisposable Subscribe(IEventHandlerFactory factory) + where TEvent : class; + + /// + /// Subscribes to an event. + /// + /// Event type + /// A factory to create/release handlers + IDisposable Subscribe(Type eventType, IEventHandlerFactory factory); + Task PublishAsync(TEvent eventData) where TEvent : class; diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventHandler.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventHandler.cs new file mode 100644 index 0000000000..8522033726 --- /dev/null +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IDistributedEventHandler.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.EventBus.Distributed +{ + public interface IDistributedEventHandler : IEventHandler + { + /// + /// Handler handles the event by implementing this method. + /// + /// Event data + Task HandleEventAsync(TEvent eventData); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs index 58b6aa20e2..fa353be5c7 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus.cs @@ -13,6 +13,36 @@ namespace Volo.Abp.EventBus.Distributed _eventBus = eventBus; } + public IDisposable Subscribe(Func action) where TEvent : class + { + return _eventBus.Register(action); + } + + public IDisposable Subscribe(IEventHandler handler) where TEvent : class + { + return _eventBus.Register(handler); + } + + public IDisposable Subscribe() where TEvent : class where THandler : IEventHandler, new() + { + return _eventBus.Register(); + } + + public IDisposable Subscribe(Type eventType, IEventHandler handler) + { + return _eventBus.Register(eventType, handler); + } + + public IDisposable Subscribe(IEventHandlerFactory factory) where TEvent : class + { + return _eventBus.Register(factory); + } + + public IDisposable Subscribe(Type eventType, IEventHandlerFactory factory) + { + return _eventBus.Register(eventType, factory); + } + public Task PublishAsync(TEvent eventData) where TEvent : class {