protected override Task ExecuteAsync(CancellationToken stoppingToken) { var consumers = ConsumerFinder.GetConsumers().ToList(); if (consumers.Any()) { consumers.ForEach(consumer => { var subscriber = new Subscriber(consumer, _serviceProvider); subscriber.StartConsuming(); }); } return(Task.CompletedTask); }
public static IServiceCollection AddRabbitMq(this IServiceCollection services, RabbitMqConfig config, params Assembly[] consumerAssemblies) { services.AddSingleton(config) .AddSingleton <IRabbitConnectionWrapper>(_ => new RabbitConnectionWrapper(config)) .AddSingleton <IMessageProducer, RabbitProducer>(); var consumers = ConsumerFinder.FindAll(consumerAssemblies); consumers.ToList().ForEach(consumer => { services.AddTransient(consumer); }); services.AddHostedService <ConsumerHost>(); return(services); }