public void Consume(ConsumeResult <string, KafkaMessage <Order> > record) { Console.WriteLine("------------------------------"); Console.WriteLine("Processing new order, checking for fraud"); Console.WriteLine(record.ToRecordString()); var order = record.Message.Value.Payload; if (IsProceed(order)) { return; } //Simulate a slow process of fraud detection Thread.Sleep(5000); if (IsFraud(order)) { SaveOrder(order, true); Console.WriteLine("Order is a fraud!!!!"); _orderDispatcher.Send(Topics.OrderReject, order.Email, order, record.Message.Value.CorrelationId.ContinueWith(ConsumerGroup)); } else { SaveOrder(order, false); Console.WriteLine("Approved: " + order); _orderDispatcher.Send(Topics.OrderApproved, order.Email, order, record.Message.Value.CorrelationId.ContinueWith(ConsumerGroup)); } }
public void Consume(ConsumeResult <string, KafkaMessage <string> > record) { Console.WriteLine("------------------------------"); Console.WriteLine("Sending email"); Console.WriteLine(record.ToRecordString()); //Simulate the email to be sent Thread.Sleep(1000); Console.WriteLine("Email sent"); }
public void Consume(ConsumeResult <string, KafkaMessage <Order> > record) { Console.WriteLine("------------------------------"); Console.WriteLine("Processing new order, preparing email"); Console.WriteLine(record.ToRecordString()); var order = record.Message.Value.Payload; var emailCode = "Thank you for your order! We are processing your order!"; var id = record.Message.Value.CorrelationId.ContinueWith(ConsumerGroup); _emailDispatcher.Send(Topics.SendEmail, order.Email, emailCode, id); }
public void Consume(ConsumeResult <string, KafkaMessage <Order> > record) { var order = record.Message.Value.Payload; Console.WriteLine("------------------------------"); Console.WriteLine("Processing new order, checking for new user"); Console.WriteLine(record.ToRecordString()); if (IsNewUser(order.Email)) { InsertNewUser(order.Email); } }
public void Consume(ConsumeResult <string, KafkaMessage <string> > record) { var topic = record.Message.Value.Payload.Trim('"'); Console.WriteLine("------------------------------"); Console.WriteLine("Processing a new batch for every user"); Console.WriteLine(record.ToRecordString()); foreach (var user in GetAllUsers()) { _dispatcher.Send(topic, user.Uuid, user, record.Message.Value.CorrelationId.ContinueWith(ConsumerGroup)); } }
public void Consume(ConsumeResult <string, KafkaMessage <User> > record) { var user = record.Message.Value.Payload; Console.WriteLine("------------------------------"); Console.WriteLine($"Processing report for {user.Uuid}"); Console.WriteLine(record.ToRecordString()); var folder = string.Empty.WithCurrentDirectory(); var sourcePath = Path.Combine(folder, "ReportModel.txt"); var targetFolder = Path.Combine(folder, "target"); Directory.CreateDirectory(targetFolder); var targetPath = Path.Combine(targetFolder, user.Uuid + ".txt"); File.Copy(sourcePath, targetPath, true); File.AppendAllLines(targetPath, new[] { $"Generated in {DateTime.Now}", $"Created for the user {user.Uuid}" }); Console.WriteLine($"File created: {targetPath}"); }