public void ConsumerData() { var conf = new ConsumerConfig { GroupId = "test-consumer-group", BootstrapServers = "localhost:9092", // Note: The AutoOffsetReset property determines the start offset in the event // there are not yet any committed offsets for the consumer group for the // topic/partitions of interest. By default, offsets are committed // automatically, so in this example, consumption will only start from the // earliest message in the topic 'my-topic' the first time you run the program. AutoOffsetReset = AutoOffsetReset.Earliest }; using (var c = new ConsumerBuilder <Ignore, string>(conf).Build()) { c.Subscribe("userReport"); CancellationTokenSource cts = new CancellationTokenSource(); Console.CancelKeyPress += (_, e) => { e.Cancel = true; // prevent the process from terminating. cts.Cancel(); }; try { while (true) { try { KisilerDatabaseSettings ksettings = new KisilerDatabaseSettings() { ApiCollectionName = "TelephoneBookCollection", ConnectionString = "mongodb://localhost:27017", DatabaseName = "Book" }; KisilerApiService kisislerService = new KisilerApiService(ksettings); var data = kisislerService.Get(); var cr = c.Consume(cts.Token); var groupedData = data.GroupBy(x => new { x.IletisimBilgisi.BilgiTipi.Konum }).Select(y => new { y.Key.Konum, Count = y.Count() }).ToList();; //// GroupedData csv ye atılır. ReportStatusDatabaseSettings settings = new ReportStatusDatabaseSettings() { ApiCollectionName = "ReportStatus", ConnectionString = "mongodb://localhost:27017", DatabaseName = "Book" }; ReportRequestService reportRequestService = new ReportRequestService(settings); var report = reportRequestService.Get(cr.Value); report.RaporDurumu = "Tamamlandı"; reportRequestService.Update(cr.Value, report); Console.WriteLine($"Consumed message '{cr.Value}' at: '{cr.TopicPartitionOffset}'."); } catch (ConsumeException e) { Console.WriteLine($"Error occured: {e.Error.Reason}"); } } } catch (OperationCanceledException) { // Ensure the consumer leaves the group cleanly and final offsets are committed. c.Close(); } } }
public ReportRequestController(ReportRequestService reportApiService) { _reportRequestService = reportApiService; }