protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await Task.Delay(2000, stoppingToken); _logger.LogInformation("Sales processor running at: {time}", DateTimeOffset.Now); if (!_firstTime) { continue; } var createScope = _serviceScopeFactory.CreateScope(); _clientReceiver = createScope.ServiceProvider.GetRequiredService <IRabbitMqClientReceiver>(); _salesFileAnalyser = createScope.ServiceProvider.GetRequiredService <ISalesFileAnalyser>(); _clientReceiver.ConfigureChannel(_configuration["RabbitMqHostName"] , _configuration["RabbitMqUsername"] , _configuration["RabbitMqPassword"] , int.Parse(_configuration["RabbitMqRetryCount"]) , _configuration["RabbitMqReceiveQueueName"]); _clientReceiver.Receive += RabbitMqClientMessageReceived; _firstTime = false; } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await Task.Delay(2000, stoppingToken); if (!_firstTime) { continue; } var createScope = _serviceScopeFactory.CreateScope(); _clientReceiver = createScope.ServiceProvider.GetRequiredService <IRabbitMqClientReceiver>(); _fileGenerator = createScope.ServiceProvider.GetRequiredService <IOutputFileGenerator>(); _clientReceiver.ConfigureChannel(_configuration["RabbitMqHostName"] , _configuration["RabbitMqUsername"] , _configuration["RabbitMqPassword"] , int.Parse(_configuration["RabbitMqRetryCount"]) , _configuration["RabbitMqReceiveQueueName"]); _clientReceiver.Receive += (sender, args) => { var outputContentDto = JsonConvert.DeserializeObject <OutputFileContentDto>(Encoding.UTF8.GetString(sender as byte[])); if (outputContentDto == null) { return; } _fileGenerator.GenerateFIle(outputContentDto); }; _firstTime = false; } }