protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                var eventTypeResolver = new EventTypeResolver();
                var viewRepo          = new CosmosDBViewRepository(_viewsEndpointUri,
                                                                   _viewsAuthKey, _viewsDatabase, _viewsContainer);


                var projectionEngine = new CosmosDBProjectionEngine(
                    eventTypeResolver, viewRepo, _processorName,
                    _eventsEndpointUri, _eventsAuthKey, _eventsDatabase,
                    _leasesEndpointUri, _leasesAuthKey, _leasesDatabase,
                    _eventsContainer, _leasesContainer, _startDateTimeUtcEpochSeconds
                    );

                projectionEngine.RegisterProjection(new OrderProjection());
                projectionEngine.RegisterProjection(new PendingOrdersProjection());
                projectionEngine.RegisterProjection(new CustomerProjection());
                projectionEngine.RegisterProjection(new AllCustomersProjection());

                var serviceName = "ProjectionWorkerService";
                await projectionEngine.StartAsync(serviceName);

                _logger.LogInformation($"{serviceName} running at: {DateTimeOffset.Now}");
                await Task.Delay(-1, stoppingToken);
            }
        }
Ejemplo n.º 2
0
        public async Task SC03B_RunProjectionsAsync()
        {
            var projectionEngine = new CosmosDBProjectionEngine(EndpointUri, AuthKey, Database);

            projectionEngine.RegisterProjection(new TotalActivatedMetersProjection());
            projectionEngine.RegisterProjection(new DailyTotalsByWeekProjection());

            await projectionEngine.StartAsync();

            await Task.Delay(-1);
        }
        public async Task RegisterProjectionsAsync()
        {
            var eventTypeResolver = new EventTypeResolver();
            var orderViewRepo     = new CosmosDBViewRepository(
                _testConfig.OrderViewsEndpointUri,
                _testConfig.OrderViewsAuthKey,
                _testConfig.OrderViewsDatabase,
                _testConfig.OrderViewsContainer);
            var orderProcessorName    = "OrderUnitTestsProcessor";
            var orderProjectionEngine = new CosmosDBProjectionEngine(eventTypeResolver, orderViewRepo, orderProcessorName,
                                                                     _testConfig.EventsEndpointUri, _testConfig.EventsAuthKey, _testConfig.EventsDatabase,
                                                                     _testConfig.LeasesEndpointUri, _testConfig.LeasesAuthKey, _testConfig.LeasesDatabase,
                                                                     _testConfig.EventContainer, _testConfig.LeasesContainer, _testConfig.StartTimeEpoch);

            orderProjectionEngine.RegisterProjection(new OrderProjection());
            orderProjectionEngine.RegisterProjection(new PendingOrdersProjection());
            await orderProjectionEngine.StartAsync("UnitTests");

            // ---
            var customerViewRepo = new CosmosDBViewRepository(
                _testConfig.CustomerViewsEndpointUri,
                _testConfig.CustomerViewsAuthKey,
                _testConfig.CustomerViewsDatabase,
                _testConfig.CustomerViewsContainer);
            var customerProcessorName    = "CustomerUnitTestsProcessor";
            var customerProjectionEngine = new CosmosDBProjectionEngine(eventTypeResolver, customerViewRepo, customerProcessorName,
                                                                        _testConfig.EventsEndpointUri, _testConfig.EventsAuthKey, _testConfig.EventsDatabase,
                                                                        _testConfig.LeasesEndpointUri, _testConfig.LeasesAuthKey, _testConfig.LeasesDatabase,
                                                                        _testConfig.EventContainer, _testConfig.LeasesContainer, _testConfig.StartTimeEpoch);

            customerProjectionEngine.RegisterProjection(new CustomerProjection());
            customerProjectionEngine.RegisterProjection(new AllCustomersProjection());

            await customerProjectionEngine.StartAsync("UnitTests");

            await Task.Delay(-1);
        }