예제 #1
0
 public EventSubscriber(string subscriptionName, IHandlerProvider handlerProvider, string[] subEndPoints)
 {
     SubscriptionName  = subscriptionName;
     HandlerProvider   = handlerProvider;
     SubEndPoints      = subEndPoints;
     _ReceiveWorkTasks = new List <Task>();
 }
예제 #2
0
        public static IMessageDispatcher Create(IHandlerProvider handlerProvider, 
                                                string dispatcherName, 
                                                params object[] args)
        {
            IMessageDispatcher messageDispatcher = ServiceLocator.Instance.GetService<IMessageDispatcher>(dispatcherName);

            IEnumerable handlers = handlerProvider.GetHandlers();

            MethodInfo methodInfo = messageDispatcher.GetType().GetMethod("Register", BindingFlags.Public | BindingFlags.Instance);

            foreach (object handlerObject in handlers)
            {
                var handlerInterfaceTypeQuery = from p in handlerObject.GetType().GetInterfaces()
                                                where p.IsGenericType &&
                                                p.GetGenericTypeDefinition().Equals(typeof(IHandler<>))
                                                select p;

                if (handlerInterfaceTypeQuery != null)
                {
                    foreach (var handlerInterfaceType in handlerInterfaceTypeQuery) 
                    {
                        Type messageType = handlerInterfaceType.GetGenericTypeDefinition();

                        MethodInfo genericRegisterMethod = methodInfo.MakeGenericMethod(messageType);

                        genericRegisterMethod.Invoke(messageDispatcher, new object[] { handlerObject });
                    }
                }
            }

            return messageDispatcher;
        }
예제 #3
0
 public DomainEventSubscriber(string name, EQueueClientsConsumers.ConsumerSetting consumerSetting,
                              string groupName, string subscribeTopic,
                              IHandlerProvider handlerProvider)
     : base(groupName, consumerSetting, groupName, subscribeTopic)
 {
     HandlerProvider = handlerProvider;
 }
예제 #4
0
 /// <summary>
 /// Parameterized constructor.
 /// </summary>
 public DefaultCommandExecutor(IHandlerProvider handerProvider,
                               IHandlerRecordStore handlerStore,
                               ITypeCodeProvider typeCodeProvider,
                               ILoggerFactory loggerFactory)
     : base(handerProvider, handlerStore, typeCodeProvider, loggerFactory)
 {
 }
예제 #5
0
        public EventSubscriber(IMessageQueueClient messageQueueClient,
                               IHandlerProvider handlerProvider,
                               ICommandBus commandBus,
                               IMessagePublisher messagePublisher,
                               string subscriptionName,
                               TopicSubscription[] topicSubscriptions,
                               string consumerId,
                               ConsumerConfig consumerConfig = null)
        {
            ConsumerConfig      = consumerConfig ?? ConsumerConfig.DefaultConfig;
            MessageQueueClient  = messageQueueClient;
            HandlerProvider     = handlerProvider;
            _topicSubscriptions = topicSubscriptions ?? new TopicSubscription[0];
            _topicSubscriptions.Where(ts => ts.TagFilter != null)
            .ForEach(ts => { TagFilters.Add(ts.Topic, ts.TagFilter); });
            ConsumerId       = consumerId;
            SubscriptionName = subscriptionName;
            MessagePublisher = messagePublisher;
            CommandBus       = commandBus;
            var loggerFactory = ObjectProviderFactory.GetService <ILoggerFactory>();

            MessageProcessor = new MailboxProcessor(new DefaultProcessingMessageScheduler(),
                                                    new OptionsWrapper <MailboxOption>(new MailboxOption
            {
                BatchCount = ConsumerConfig.MailboxProcessBatchCount
            }),
                                                    loggerFactory.CreateLogger <MailboxProcessor>());
            Logger = loggerFactory.CreateLogger(GetType().Name);
        }
예제 #6
0
        public static IMessageDispatcher Create(IHandlerProvider handlerProvider,
                                                string dispatcherName,
                                                params object[] args)
        {
            IMessageDispatcher messageDispatcher = ServiceLocator.Instance.GetService <IMessageDispatcher>(dispatcherName);

            IEnumerable handlers = handlerProvider.GetHandlers();

            MethodInfo methodInfo = messageDispatcher.GetType().GetMethod("Register", BindingFlags.Public | BindingFlags.Instance);

            foreach (object handlerObject in handlers)
            {
                var handlerInterfaceTypeQuery = from p in handlerObject.GetType().GetInterfaces()
                                                where p.IsGenericType &&
                                                p.GetGenericTypeDefinition().Equals(typeof(IHandler <>))
                                                select p;

                if (handlerInterfaceTypeQuery != null)
                {
                    foreach (var handlerInterfaceType in handlerInterfaceTypeQuery)
                    {
                        Type messageType = handlerInterfaceType.GetGenericTypeDefinition();

                        MethodInfo genericRegisterMethod = methodInfo.MakeGenericMethod(messageType);

                        genericRegisterMethod.Invoke(messageDispatcher, new object[] { handlerObject });
                    }
                }
            }

            return(messageDispatcher);
        }
예제 #7
0
 public CommandProcessorFactory(
     IHandlerProvider <TSession, TConnection> handlerProvider,
     ICommandExecutor <TConnection> commandExecutor
     )
 {
     _handlerProvider = handlerProvider ?? throw new ArgumentNullException(nameof(handlerProvider));
     _commandExecutor = commandExecutor ?? throw new ArgumentNullException(nameof(commandExecutor));
 }
예제 #8
0
 public EventSubscriber(string subscriptionName, IHandlerProvider handlerProvider, string[] subEndPoints)
     : base(handlerProvider, subscriptionName)
 {
     SubEndPoints      = subEndPoints;
     _ReceiveWorkTasks = new List <Task>();
     MessageQueue      = new BlockingCollection <IMessageContext>();
     _Logger           = IoCFactory.Resolve <ILoggerFactory>().Create(this.GetType());
 }
예제 #9
0
 public CommandConsumer(IHandlerProvider handlerProvider, string receiveEndPoint)
     : base(handlerProvider)
 {
     MessageQueue    = new BlockingCollection <IMessageContext>();
     ReceiveEndPoint = receiveEndPoint;
     ReplySenders    = new Dictionary <string, ZmqSocket>();
     _Logger         = IoCFactory.Resolve <ILoggerFactory>().Create(this.GetType());
 }
예제 #10
0
 public NotificationPublisher(
     IHandlerProvider <TSession, TConnection> handlerProvider,
     INotificationExecutor <TSession> executor
     )
 {
     _handlerProvider = handlerProvider ?? throw new ArgumentNullException(nameof(handlerProvider));
     _executor        = executor ?? throw new ArgumentNullException(nameof(executor));
 }
예제 #11
0
 public QueryProcessor(
     IHandlerProvider <TSession, TConnection> handlerProvider,
     IQueryExecutor <TConnection> executor
     )
 {
     _handlerProvider = handlerProvider ?? throw new ArgumentNullException(nameof(handlerProvider));
     _executor        = executor ?? throw new ArgumentNullException(nameof(executor));
 }
예제 #12
0
 public EventSubscriber(string subscriptionName, IHandlerProvider handlerProvider, string[] subEndPoints)
     : base(handlerProvider, subscriptionName)
 {
     SubEndPoints = subEndPoints;
     _ReceiveWorkTasks = new List<Task>();
     MessageQueue = new BlockingCollection<IMessageContext>();
     _Logger = IoCFactory.Resolve<ILoggerFactory>().Create(this.GetType());
 }
예제 #13
0
 public RabbitMqEventBus(ConnectionFactory connectionFactory, IHandlerProvider handlerProvider, IMessageProvider messageProvider = null, INameProvider nameProvider = null)
 {
     connectionProvider   = new ConnectionProvider(connectionFactory);
     subscriptionManager  = new SubscriptionManager();
     this.handlerProvider = handlerProvider;
     this.messageProvider = messageProvider ?? new JsonMessageProvider();
     this.nameProvider    = nameProvider ?? new DefaultQueueNameProvider();
 }
예제 #14
0
 public CommandConsumer(IHandlerProvider handlerProvider, string receiveEndPoint)
     : base(handlerProvider)
 {
     MessageQueue = new BlockingCollection<IMessageContext>();
     ReceiveEndPoint = receiveEndPoint;
     ReplySenders = new Dictionary<string, ZmqSocket>();
     _Logger = IoCFactory.Resolve<ILoggerFactory>().Create(this.GetType());
 }
예제 #15
0
        /// <summary>
        /// Mediator constructor
        /// </summary>
        /// <param name="provider">Event and query handlers provider</param>
        /// <param name="middlewareProvider">Event and query middlewares provider</param>
        /// <param name="eventDispatchStrategy">Event dispatching strategy to use</param>
        public Mediator(IHandlerProvider provider, IMiddlewareProvider middlewareProvider, IEventDispatchStrategy eventDispatchStrategy)
        {
            _queryHandlerProvider  = provider;
            _eventHandlerProvider  = provider;
            _eventDispatchStrategy = eventDispatchStrategy;

            _queryMiddlewareProvider = middlewareProvider;
            _eventMiddlewareProvider = middlewareProvider;
        }
예제 #16
0
 public CommandConsumer(IHandlerProvider handlerProvider,
                        string serviceBusConnectionString,
                        string commandQueueName)
     : base(serviceBusConnectionString)
 {
     _handlerProvider  = handlerProvider;
     _commandQueueName = commandQueueName;
     _replyProducers   = new Dictionary <string, TopicClient>();
 }
예제 #17
0
 public CommandConsumer(IHandlerProvider handlerProvider,
     IMessagePublisher messagePublisher,
     string commandQueueName)
 {
     _commandQueueName = commandQueueName;
     _handlerProvider = handlerProvider;
     _messagePublisher = messagePublisher;
     _messageQueueClient = IoCFactory.Resolve<IMessageQueueClient>();
     _logger = IoCFactory.Resolve<ILoggerFactory>().Create(this.GetType());
 }
예제 #18
0
 /// <summary>
 /// Parameterized Constructor.
 /// </summary>
 public MessageExecutor(IHandlerProvider handlerProvider,
                        IHandlerRecordStore handlerStore,
                        ITypeCodeProvider typeCodeProvider,
                        ILoggerFactory loggerFactory)
 {
     this._handlerProvider  = handlerProvider;
     this._handlerStore     = handlerStore;
     this._typeCodeProvider = typeCodeProvider;
     this._logger           = loggerFactory.GetOrCreate("Cqrs");
 }
예제 #19
0
 public CommandConsumer(IHandlerProvider handlerProvider,
                        IMessagePublisher messagePublisher,
                        string commandQueueName)
 {
     _commandQueueName   = commandQueueName;
     _handlerProvider    = handlerProvider;
     _messagePublisher   = messagePublisher;
     _messageQueueClient = IoCFactory.Resolve <IMessageQueueClient>();
     _logger             = IoCFactory.Resolve <ILoggerFactory>().Create(this.GetType());
 }
예제 #20
0
 public EventSubscriber(string serviceBusConnectionString,
                        IHandlerProvider handlerProvider,
                        string subscriptionName,
                        params string[] topics)
     : base(serviceBusConnectionString)
 {
     _handlerProvider  = handlerProvider;
     _topics           = topics;
     _subscriptionName = subscriptionName;
     _consumeWorkTasks = new List <Task>();
 }
예제 #21
0
        private static T GetHandlerFromObject <T>(object obj) where T : class
        {
            IHandlerProvider <T> handlerProvider = obj as IHandlerProvider <T>;

            if (handlerProvider != null)
            {
                return(handlerProvider.Handler);
            }

            return(obj as T);
        }
예제 #22
0
 public EventSubscriber(string serviceBusConnectionString,
     IHandlerProvider handlerProvider,
     string subscriptionName,
     params string[] topics)
     : base(handlerProvider, subscriptionName)
 {
     _serviceBusClient = new ServiceBusClient(serviceBusConnectionString);
     _handlerProvider = handlerProvider;
     _topics = topics;
     _subscriptionName = subscriptionName;
     _consumeWorkTasks = new List<Task>();
 }
예제 #23
0
 /// <summary>
 /// Register an instance of IHandlerProvider which will provide handlers for raised events.
 /// Multiple handler providers may be registered.
 /// </summary>
 /// <param name="handlerProvider"></param>
 public void RegisterProvider(IHandlerProvider handlerProvider)
 {
     if (handlerProvider == null)
     {
         throw new ArgumentNullException(nameof(handlerProvider));
     }
     if (_handlerProviders.Contains(handlerProvider))
     {
         return;
     }
     _handlerProviders.Add(handlerProvider);
 }
예제 #24
0
        public CommandConsumer(string name, EQueueClientsConsumers.ConsumerSetting consumerSetting, string groupName,
                               string subscribeTopic, string brokerAddress, int producerBrokerPort,
                               IHandlerProvider handlerProvider)
            : base(name, consumerSetting, groupName, subscribeTopic)
        {
            HandlerProvider = handlerProvider;
            var producerSetting = new EQueueClientsProducers.ProducerSetting();

            producerSetting.BrokerAddress = brokerAddress;
            producerSetting.BrokerPort    = producerBrokerPort;
            Producer = new EQueueClientsProducers.Producer(string.Format("{0}-Reply-Producer", name), producerSetting);
            CommandConsumers.Add(this);
        }
예제 #25
0
        //public static async Task<T> HandleAsync<T>(this IHandlerProvider handlerProvider, IResolverSession session,
        //    string scopeId, string actionId, object[] requests, CancellationToken cancellationToken)
        //{
        //    var actionBytes = new byte[4];
        //    actionBytes.AddBytes<int>(actionId, 4, 0);

        //    return await HandleAsync<T>(handlerProvider, session, scopeId, actionBytes, requests, cancellationToken);
        //}

        public static async Task <T> HandleAsync <T>(this IHandlerProvider handlerProvider, IResolverSession session,
                                                     string scopeId, string actionId, object[] requests, CancellationToken cancellationToken)
        {
            var parameterTypes = requests.Where(r => !(r is CancellationToken)).Select(r => r.GetType()).ToArray();
            var returnType     = typeof(T);
            var parameterHash  = TypeHasher.GetMethodBytes(parameterTypes, returnType, t => t.Name);

            //var scopeBytes = Encoding.UTF8.GetBytes(scopeId);
            var actionHash = TypeHasher.CreateMD5Hash(Encoding.UTF8.GetBytes($"scope-{scopeId}:action-{actionId}"), parameterHash);

            var handler = handlerProvider.GetHandler(actionHash.ToByteArray());

            return((T)await handler.HandleAsync(session, requests, cancellationToken));
        }
예제 #26
0
 public EventSubscriber(IMessageQueueClient messageQueueClient,
                        IHandlerProvider handlerProvider,
                        ICommandBus commandBus,
                        IMessagePublisher messagePublisher,
                        string subscriptionName,
                        params string[] topics)
 {
     _MessageQueueClient = messageQueueClient;
     _handlerProvider    = handlerProvider;
     _topics             = topics;
     _subscriptionName   = subscriptionName;
     _messagePublisher   = messagePublisher;
     _commandBus         = commandBus;
     _logger             = IoCFactory.Resolve <ILoggerFactory>().Create(this.GetType());
 }
예제 #27
0
        public MethodProtocolHandler(IHandlerProvider handlerProvider, IResolverSession resolverSession)
        {
            if (handlerProvider == null)
            {
                throw new ArgumentNullException(nameof(handlerProvider));
            }

            if (resolverSession == null)
            {
                throw new ArgumentNullException(nameof(resolverSession));
            }

            this.handlerProvider = handlerProvider;
            //this.resolverSession = resolverSession;
        }
예제 #28
0
 public EventSubscriber(IMessageQueueClient messageQueueClient,
     IHandlerProvider handlerProvider,
     ICommandBus commandBus,
     IMessagePublisher messagePublisher,
     string subscriptionName,
     params string[] topics)
 {
     _MessageQueueClient = messageQueueClient;
     _handlerProvider = handlerProvider;
     _topics = topics;
     _subscriptionName = subscriptionName;
     _messagePublisher = messagePublisher;
     _commandBus = commandBus;
     _logger = IoCFactory.Resolve<ILoggerFactory>().Create(this.GetType());
 }
예제 #29
0
 public EventSubscriber(IMessageQueueClient messageQueueClient,
                        IHandlerProvider handlerProvider,
                        ICommandBus commandBus,
                        IMessagePublisher messagePublisher,
                        string subscriptionName,
                        string topic,
                        string consumerId)
 {
     _MessageQueueClient = messageQueueClient;
     _handlerProvider    = handlerProvider;
     _topic            = topic;
     _consumerId       = consumerId;
     _subscriptionName = subscriptionName;
     _messagePublisher = messagePublisher;
     _commandBus       = commandBus;
     _messageProcessor = new MessageProcessor(new DefaultProcessingMessageScheduler <IMessageContext>());
     _logger           = IoCFactory.Resolve <ILoggerFactory>().Create(this.GetType());
 }
예제 #30
0
 public CommandConsumer(IMessageQueueClient messageQueueClient,
                        IMessagePublisher messagePublisher,
                        IHandlerProvider handlerProvider,
                        string commandQueueName,
                        string consumerId,
                        ConsumerConfig consumerConfig = null)
 {
     _consumerConfig          = consumerConfig ?? ConsumerConfig.DefaultConfig;
     _commandQueueName        = commandQueueName;
     _handlerProvider         = handlerProvider;
     _messagePublisher        = messagePublisher;
     _consumerId              = consumerId;
     _cancellationTokenSource = new CancellationTokenSource();
     _messageQueueClient      = messageQueueClient;
     _messageProcessor        = new MessageProcessor(new DefaultProcessingMessageScheduler <IMessageContext>(),
                                                     _consumerConfig.MailboxProcessBatchCount);
     _logger = IoCFactory.IsInit() ? IoCFactory.Resolve <ILoggerFactory>().Create(GetType().Name) : null;
 }
		public PipelineBuilder(
			[NotNull]BusSettings busSettings,
			[NotNull]IHandlerProvider handlerProvider,
			[NotNull]IGlobalPipelineProvider globalPipelineProvider,
			[NotNull]IGlobalPipelineTracker tracker,
			[NotNull]IDependencyScope dependencyScope)
		{
			if (handlerProvider == null) throw new ArgumentNullException(nameof(handlerProvider));
			if (globalPipelineProvider == null) throw new ArgumentNullException(nameof(globalPipelineProvider));
			if (tracker == null) throw new ArgumentNullException(nameof(tracker));
			if (dependencyScope == null) throw new ArgumentNullException(nameof(dependencyScope));
			if (busSettings == null) throw new ArgumentNullException(nameof(busSettings));

			this.handlerProvider = handlerProvider;
			this.globalPipelineProvider = globalPipelineProvider;
			this.tracker = tracker;
			this.dependencyScope = dependencyScope;
			this.busSettings = busSettings;
		}
예제 #32
0
 public CommandConsumer(IMessageQueueClient messageQueueClient,
                        IMessagePublisher messagePublisher,
                        IHandlerProvider handlerProvider,
                        string commandQueueName,
                        string consumerId,
                        int fullLoadThreshold = 1000,
                        int waitInterval      = 1000)
 {
     _fullLoadThreshold       = fullLoadThreshold;
     _waitInterval            = waitInterval;
     _commandQueueName        = commandQueueName;
     _handlerProvider         = handlerProvider;
     _messagePublisher        = messagePublisher;
     _consuemrId              = consumerId;
     _cancellationTokenSource = new CancellationTokenSource();
     _messageQueueClient      = messageQueueClient;
     _messageProcessor        = new MessageProcessor(new DefaultProcessingMessageScheduler <IMessageContext>());
     _logger = IoCFactory.Resolve <ILoggerFactory>().Create(this.GetType());
 }
예제 #33
0
 public EventSubscriber(IMessageQueueClient messageQueueClient,
                        IHandlerProvider handlerProvider,
                        ICommandBus commandBus,
                        IMessagePublisher messagePublisher,
                        string subscriptionName,
                        string topic,
                        string consumerId,
                        ConsumerConfig consumerConfig = null)
 {
     _consumerConfig     = consumerConfig ?? ConsumerConfig.DefaultConfig;
     _messageQueueClient = messageQueueClient;
     _handlerProvider    = handlerProvider;
     _topic            = topic;
     _consumerId       = consumerId;
     _subscriptionName = subscriptionName;
     _messagePublisher = messagePublisher;
     _commandBus       = commandBus;
     _messageProcessor = new MessageProcessor(new DefaultProcessingMessageScheduler <IMessageContext>(),
                                              _consumerConfig.MailboxProcessBatchCount);
     _logger = IoCFactory.IsInit() ? IoCFactory.Resolve <ILoggerFactory>().Create(GetType().Name) : null;
 }
예제 #34
0
        public CommandProcessor(IMessageQueueClient messageQueueClient,
                                IMessagePublisher messagePublisher,
                                IHandlerProvider handlerProvider,
                                string commandQueueName,
                                string consumerId,
                                ConsumerConfig consumerConfig = null)
        {
            ConsumerConfig          = consumerConfig ?? ConsumerConfig.DefaultConfig;
            CommandQueueName        = commandQueueName;
            HandlerProvider         = handlerProvider;
            MessagePublisher        = messagePublisher;
            ConsumerId              = consumerId;
            CancellationTokenSource = new CancellationTokenSource();
            MessageQueueClient      = messageQueueClient;
            var loggerFactory = ObjectProviderFactory.GetService <ILoggerFactory>();

            MessageProcessor = new MailboxProcessor(new DefaultProcessingMessageScheduler(),
                                                    new OptionsWrapper <MailboxOption>(new MailboxOption
            {
                BatchCount = ConsumerConfig.MailboxProcessBatchCount
            }),
                                                    loggerFactory.CreateLogger <MailboxProcessor>());
            Logger = loggerFactory.CreateLogger(GetType().Name);
        }
예제 #35
0
 public Mediator(IHandlerProvider handlerProvider)
 {
     this._handlerProvider = handlerProvider;
 }
예제 #36
0
 public CommandConsumerBase(IHandlerProvider handlerProvider)
 {
     _handlerProvider = handlerProvider;
     _logger = IoCFactory.Resolve<ILoggerFactory>().Create(this.GetType());
 }
예제 #37
0
파일: Bus.cs 프로젝트: kouweizhong/SeptaBus
 public Bus(IHandlerProvider handlerProvider, IMessageDecoratorProvider decoratorProvider)
 {
     _handlerProvider   = handlerProvider;
     _decoratorProvider = decoratorProvider;
 }
 public CommandToHandlerMapper(IHandlerProvider handlerProvider)
 {
     _handlerProvider = handlerProvider;
 }
예제 #39
0
 public void AddProvider(string name, IHandlerProvider provider)
 {
     this.providers.Add(name, provider.SetDependencyProvider(_provider));
 }
예제 #40
0
 public static async Task <T> HandleAsync <T>(this IHandlerProvider handlerProvider, IResolverSession session,
                                              string scopeId, string actionId, params object[] requests)
 {
     //var actionBytes = Encoding.UTF8.GetBytes(actionId);
     return(await HandleAsync <T>(handlerProvider, session, scopeId, actionId, requests, CancellationToken.None));
 }