Beispiel #1
0
        private void RabbitMqOnMessageReceived(object sender, EventArgs e)
        {
            var outputContentDto =
                JsonConvert.DeserializeObject <OutputFileContentDto>(Encoding.UTF8.GetString(sender as byte[]));

            if (outputContentDto == null)
            {
                return;
            }

            _fileGenerator.GenerateFIle(outputContentDto);
        }
Beispiel #2
0
        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;
            }
        }