Ejemplo n.º 1
0
        public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T>
        {
            var eventName = _subscriptionsManager.GetEventKey <T>();

            if (!_persistentConnection.IsConnected)
            {
                _persistentConnection.TryConnect();
            }

            var hasSubs = _subscriptionsManager.HasSubscriptionsForEvent(eventName);

            if (!hasSubs)
            {
                using (var channel = _persistentConnection.CreateModel())
                {
                    channel.QueueBind(_queueName,
                                      exchange: _brokerName,
                                      routingKey: eventName);
                }
            }

            _logger.LogInformation("Subscribing to event {EventName} with {EventHandler}", eventName, typeof(TH).Name);

            _subscriptionsManager.AddSubscription <T, TH>();
            StartBasicConsume();
        }
Ejemplo n.º 2
0
        public void Subscribe <T, TH>()
            where T : EventArguments
            where TH : IEventHandler <T>
        {
            var eventName = _subsManager.GetEventKey <T>();

            DoInternalSubscription(eventName);
            _subsManager.AddSubscription <T, TH>();
        }
Ejemplo n.º 3
0
        public void Subscribe <TIntegrationEvent, TIntegrationEventHandler>()
            where TIntegrationEvent : IntegrationEvent
            where TIntegrationEventHandler : IIntegrationEventHandler <TIntegrationEvent>
        {
            var eventName = _subscriptionsManager.GetEventKey <TIntegrationEvent>();

            DoInternalSubscription(eventName);
            _subscriptionsManager.AddSubscription <TIntegrationEvent, TIntegrationEventHandler>();
        }
Ejemplo n.º 4
0
        public void Subscribe <T, TH>() where T : DefaultEvent where TH : IEventHandler <T>
        {
            var eventName = subscriptionManager.GetEventKey <T>();

            DoInternalSubscription(eventName);

            subscriptionManager.AddSubscription <T, TH>();
            StartConsumer();
        }
Ejemplo n.º 5
0
        public void Subscribe <T, TH>()
            where T : Event
            where TH : IEventHandler <T>
        {
            var eventName = _subsManager.GetEventKey <T>();

            DoInternalSubscription(eventName);

            _logger.LogInformation("Subscribing to event {EventName} with {EventHandler}", eventName, typeof(TH).Name);

            _subsManager.AddSubscription <T, TH>();
            StartBasicConsume();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Subscribe to the Event type
        /// </summary>
        /// <param name="handler">Handler</param>
        /// <typeparam name="T">Event type</typeparam>
        /// <typeparam name="TH">Handler type</typeparam>
        /// <returns>Subscription guid</returns>
        public string Subscribe <T, TH>(Func <TH> handler)
            where T : IntegrationEvent
            where TH : IIntegrationEventHandler <T>
        {
            if (!_subscriptionsManager.HasEventTopic <T>())
            {
                return(string.Empty);
            }

            var model = _integrationEventsRespository.SetModelAsync <T, TH>();

            if (model == null)
            {
                throw new Exception($"Error on subscription to the integration event {typeof(T).Name}");
            }

            return(_subscriptionsManager.AddSubscription <T, TH>(handler));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEvent"></typeparam>
        /// <typeparam name="TEventHandler"></typeparam>
        public void RegisterEventHandler <TEvent, TEventHandler>()
            where TEventHandler : IEventHandler <TEvent>
        {
            var eventName = subscriptionsManager.GetEventKey <TEvent>();

            if (subscriptionsManager.HasSubscriptions(eventName))
            {
                return;
            }

            if (!connection.IsConnected)
            {
                connection.TryConnect();
            }

            using var model = connection.CreateModel();
            model.QueueBind(
                queue: settings.QueueName,
                exchange: BROKER_NAME,
                routingKey: eventName);

            subscriptionsManager.AddSubscription <TEvent, TEventHandler>();
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TEvent"></typeparam>
 /// <typeparam name="TEventHandler"></typeparam>
 public void RegisterEventHandler <TEvent, TEventHandler>()
     where TEventHandler : IEventHandler <TEvent>
 {
     subscriptionsManager.AddSubscription <TEvent, TEventHandler>();
 }