private async Task ProcessEvent(string eventName, string message)
        {
            if (eventBusSubscribeManager.HasSubscribeForEvent(eventName))
            {
                using (var scope = lifetimeScope.BeginLifetimeScope())
                {
                    var subscribes = eventBusSubscribeManager.GetHandlersForEvent(eventName);
                    foreach (var subscribe in subscribes)
                    {
                        var handler = scope.ResolveOptional(subscribe.HandlerType);
                        if (handler == null)
                        {
                            continue;
                        }
                        var eventType = eventBusSubscribeManager.GetEventTypeByName(eventName);
                        if (eventType == null)
                        {
                            continue;
                        }
                        var integrationEvent = JsonConvert.DeserializeObject(message, eventType);
                        var concreteType     = typeof(IIntegrationEventHandler <>).MakeGenericType(eventType);

                        await Task.Yield();

                        await(Task) concreteType.GetMethod("Handle").Invoke(handler, new object[] { integrationEvent });
                    }
                }
            }
        }
Example #2
0
        private void DoInternalSubscribe(string eventName)
        {
            if (!eventBusSubscribeManager.HasSubscribeForEvent(eventName))
            {
                if (!redisConnection.IsConnected)
                {
                    redisConnection.TryConnect();
                }

                if (redisConnection.IsConnected)
                {
                    var         multiplexer = redisConnection.GetInstance();
                    ISubscriber sub         = multiplexer.GetSubscriber();
                    sub.Subscribe(eventName, Consumer_ReceivedAsync);
                }
            }
        }