public void ConfigureConsumer(CancellationToken cancellationToken)
        {
            using (var consumer = new ConsumerBuilder <Ignore, string>(_consumerConfig).Build())
            {
                consumer.Subscribe(SaleAnalysisInputTopic);

                try
                {
                    while (!cancellationToken.IsCancellationRequested)
                    {
                        try
                        {
                            var cr           = consumer.Consume(cancellationToken);
                            var salesSummary = _saleDataProcessor.Process(cr.Value);
                            SendResponse(salesSummary, cr.Headers);
                        }
                        catch (ConsumeException e)
                        {
                            Console.WriteLine($"Error occured: {e.Error.Reason}");
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                    // Ensure the consumer leaves the group cleanly and final offsets are committed.
                    consumer.Close();
                }
            }
        }
Exemple #2
0
        public void ProcessFile(string filePath)
        {
            var fileContent = File.ReadAllText(filePath);

            _saleDataProcessor.Process(fileContent, Path.GetFileName(filePath));
        }