private void ConfigureRabbitMq(IServiceCollection services) { var config = new RabbitMqConfig(); Configuration.GetSection("RabbitMq").Bind(config); var factory = RabbitMqFactory.Create(config); var publishers = new Dictionary <string, IPublisher>(); publishers.Add(Queues.APIGateway, factory.CreatePublisher(Queues.APIGateway)); publishers.Add(Queues.Transactions, factory.CreatePublisher(Queues.Transactions)); var publishingRouter = new PublishingRouter(publishers); services.AddSingleton(new PublishingRouter(publishers)); var servicesProvider = services.BuildServiceProvider(); var logger = servicesProvider.GetService <ILogger <IConsumer> >(); var paymentsService = servicesProvider.GetService <PaymentsService>(); var consumingRouter = ConsumingRouter <PaymentsService> .Create(paymentsService, publishingRouter, "Payments", logger); var consumer = factory.CreateConsumer(Queues.Payments); consumingRouter.LinkConsumer(consumer); services.AddSingleton(consumingRouter); }
private void ConfigureRabbitMq(IServiceCollection services, ServiceProvider loggerServicesProvier) { var config = new RabbitMqConfig(); Configuration.GetSection("RabbitMq").Bind(config); var factory = RabbitMqFactory.Create(config); var cardsConsumer = factory.CreateConsumer(Queues.Cards); var awaiter = new EventsAwaiter("Cards", loggerServicesProvier.GetService <ILogger <EventsAwaiter> >()); awaiter.BindConsumer(cardsConsumer); services.AddSingleton(awaiter); var publishers = new Dictionary <string, IPublisher>(); publishers.Add(Queues.APIGateway, factory.CreatePublisher(Queues.APIGateway)); publishers.Add(Queues.Accounts, factory.CreatePublisher(Queues.Accounts)); publishers.Add(Queues.Transactions, factory.CreatePublisher(Queues.Transactions)); var publishingRouter = new PublishingRouter(publishers); services.AddSingleton(publishingRouter); var servicesProvider = services.BuildServiceProvider(); var cardsService = servicesProvider.GetService <CardsService>(); var consumingRouter = ConsumingRouter <CardsService> .Create(cardsService, publishingRouter, "Cards", loggerServicesProvier.GetService <ILogger <IConsumer> >()); consumingRouter.LinkConsumer(cardsConsumer); services.AddSingleton(consumingRouter); }