private void Subscribe(RabbitMqEventConsumerFactory eventConsumerFactory) { string toCamel(string s) => Char.ToLower(s[0]) + s.Substring(1); string messageName = toCamel(eventConsumerFactory.MessageName); Func <IEventConsumer> factory = eventConsumerFactory.FactoryFunc; _logger.LogDebug("Initializing subscriber: {s}", messageName); var subscription = _bus.Subscribe(typeof(IAppEvent <Event>), messageName, o => { _logger.LogDebug("Received message from MQ: {name}", messageName); factory .Invoke() .Dispatch(o); }, configuration => { configuration.WithTopic(messageName); configuration.WithQueueName(messageName); }); _subscriptions.Add(subscription); }
internal void InitSubscribers(string assemblyName, IImplProvider implProvider) { SetupErrorQueueSubscribtion(); var eventConsumerTypes = Assembly.Load(assemblyName) .GetTypes() .Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(EventConsumer <>)) .ToArray(); _logger.LogDebug("Found EventConsumers {list} in assembly: {assemblyName}", eventConsumerTypes.Select(f => f.Name).ToArray(), assemblyName); foreach (var consumerType in eventConsumerTypes) { var evType = consumerType.BaseType.GetGenericArguments()[0]; var factory = new RabbitMqEventConsumerFactory(() => (IEventConsumer)implProvider.Get(consumerType), evType.Name); Subscribe(factory); } }