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);
        }
예제 #2
0
        private void AddAwaiter(IServiceCollection services, RabbitMqFactory factory, ServiceProvider loggerServicesProvier)
        {
            var awaiter = new EventsAwaiter("APIGateway", loggerServicesProvier.GetService <ILogger <EventsAwaiter> >());

            var consumer = factory.CreateConsumer(Queues.APIGateway);

            awaiter.BindConsumer(consumer);

            services.AddSingleton(awaiter);
        }