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 ActionResult <string> Get() { _batchDispatcher.Send(Topics.SendMessageToAllUsers, Topics.UserGenerateReadingReport, Topics.UserGenerateReadingReport, new CorrelationId(nameof(AdminController))); Console.WriteLine("Sent generate reports to all users"); return(Ok("Sent generate reports to all users")); }
public ActionResult <string> Get([FromQuery] string email, [FromQuery] double amount) { var id = new CorrelationId(nameof(NewOrderController)); var orderId = Guid.NewGuid().ToString(); var order = new Order(orderId, amount, email); _orderDispatcher.Send(Topics.NewOrder, email, order, id); Console.WriteLine("New order sent succesfully"); return(Ok("New order sent succesfully")); }
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 <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 static void Main(string[] args) { using var orderDispatcher = new KafkaDispatcher <Order>(); using var emailDispatcher = new KafkaDispatcher <string>(); var random = new Random(); var email = random.NextDouble() + "@mailinator.com"; for (int i = 0; i < 10; i++) { var orderId = Guid.NewGuid().ToString(); var amount = random.NextDouble() * 5000 + 1; var id = new CorrelationId(nameof(GenerateOrders)); var order = new Order(orderId, amount, email); orderDispatcher.Send(Topics.NewOrder, email, order, id); } }