Exemplo n.º 1
0
        public static MassTransitConfiguration GetMassTransitConfiguration(this IConfiguration configuration)
        {
            var hostConfig = new MassTransitConfiguration();

            configuration.GetSection(MassTransit).Bind(hostConfig);

            return(hostConfig);
        }
Exemplo n.º 2
0
        public async Task SendBookRequest(int booksCount)
        {
            var message = new BooksRequest(booksCount);

            var hostConfig = new MassTransitConfiguration();

            _configuration.GetSection("MassTransit").Bind(hostConfig);
            var endpoint = await _sendEndpointProvider.GetSendEndpoint(hostConfig.GetQueueAddress("book-shop-queue"));

            await endpoint.Send(message);
        }
Exemplo n.º 3
0
        public async Task SendBooksToQueue(List <IBooksResponse.Book> books)
        {
            var message = new BooksResponse {
                Books = books
            };
            var hostConfig = new MassTransitConfiguration();

            _configuration.GetSection("MassTransit").Bind(hostConfig);
            var endpoint = await _sendEndpointProvider.GetSendEndpoint(hostConfig.GetQueueAddress("books-delivery-queue"));

            await endpoint.Send(message);
        }
Exemplo n.º 4
0
        public async Task SentBookRequest(int bookCount)
        {
            Console.Out.WriteLine("Запрос на книги");
            var message = new BookRequest(bookCount);

            var hostConfig = new MassTransitConfiguration();

            _configuration.GetSection("MassTransit").Bind(hostConfig);
            var endpoint = await _sendEndpointProvider.GetSendEndpoint(hostConfig.GetQueueAddress("book-shop-queue"));

            await endpoint.Send(message);
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            PrometheusMetrics.TryConfigure(Environment.ApplicationName);
            MapEvents();

            var esConnection = ConfigureEsConnection(
                Configuration["EventStore:ConnectionString"],
                Environment.ApplicationName);

            var store =
                new MeasuredStore(
                    new AggregateStore(esConnection));

            var customerService = new CustomerCommandService(store);

            var bus =
                MassTransitConfiguration.ConfigureBus(
                    "rabbitmq://localhost", "guest", "guest",
                    ("talk-customer", ep =>
            {
                ep.Handler <Messages.Customer.Commands.RegisterCustomer>(
                    ctx => customerService.Handle(ctx.Message));
            }));

            services.AddMassTransit(bus);

            var reactorsSubscriptionManager = new SubscriptionManager(
                esConnection,
                new EsCheckpointStore(esConnection, "reactors-checkpoint"),
                "commandsReactors",
                ConfigureReactors()
                );

            services.AddSingleton <IHostedService>(
                new EventStoreService(
                    esConnection,
                    reactorsSubscriptionManager)
                );

            Log.SetLoggerFactory(LoggerFactory);
            services.AddSingleton <IHostedService>(provider =>
                                                   new ProtoClusterHostedService(
                                                       new Uri(Configuration["Proto:ConsulUrl"]),
                                                       Configuration["Proto:ClusterName"],
                                                       "localhost",
                                                       Configuration.GetValue <int>("Proto:NodePort"),
                                                       esConnection));
        }
        public static MassTransitConfiguration GetMassTransitConfiguration(this IConfiguration configuration)
        {
                        #warning можно так сделать, да, а можно ещё красивее

            /*
             * services.Configure<MassTransitConfiguration>(configuration.GetSection("MassTransit"));
             * services.AddSingleton<IMassTransitConfiguration>(isp => isp.GetRequiredService<IOptions<MassTransitConfiguration>>().Value);
             *
             */
                        #warning т.е. просто зарегать в DI IMassTransitConfiguration, и инжектить куда надо.
                        #warning но, пожалуй, в этом случае это был бы оверинжиниринг
            var hostConfig = new MassTransitConfiguration();
            configuration.GetSection(MassTransit).Bind(hostConfig);

            return(hostConfig);
        }