Ejemplo n.º 1
0
        private async Task ProcessEvent(string eventName, string message)
        {
            if (!_subscriptionManager.HasSubscriptionForEvent(eventName))
            {
                using (var scope = _autofacScope.BeginLifetimeScope(AUTOFAC_SCOPE_NAME))
                {
                    var subscriptions = _subscriptionManager.GetHandlersForEvent(eventName);

                    foreach (var sub in subscriptions)
                    {
                        var handler = scope.ResolveOptional(sub.HandlerType);
                        if (sub.IsDynamic)
                        {
                            var     dynamicHandler = handler as IDynamicIntegrationEventHandler;
                            dynamic eventData      = JObject.Parse(message);
                            await dynamicHandler.Handle(eventData);
                        }
                        else
                        {
                            var eventType        = _subscriptionManager.GetEventTypeByName(eventName);
                            var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
                            var concreteType     = typeof(IIntegrationEventHandler <>).MakeGenericType(eventType);
                            await(Task) concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void DoInternalSubscription(string eventName)
        {
            var containsKey = _subscriptionManager.HasSubscriptionForEvent(eventName);

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

                using (var channel = _persistentConnection.CreateModel())
                {
                    channel.QueueBind(queue: _queueName,
                                      exchange: BROKER_NAME,
                                      routingKey: eventName);
                }
            }
        }