public void TestMethod1() { //Setup Order var pizzas = new List <Pizza>(); pizzas.Add(new Pizza { Id = 1, Status = PizzaStatus.Prep }); pizzas.Add(new Pizza { Id = 2, Status = PizzaStatus.Prep }); var order = new Order { CustomerName = "test", Pizza = pizzas }; order.Id = 0; order.Status = Status.Started; IStreamProcessingQueue queue = new KafkaStreamProcessing(); queue.QueueOrder(order); //queue.RetrieveOrders(1); // Assert.AreEqual(orders.First().CustomerName, "test"); }
public IHttpActionResult Post(OrderDTO orderDTO) { Order order = _mapper.Map <OrderDTO, Order>(orderDTO); order.Status = Status.Started; order.CreateDate = DateTime.Now; BetterRandom random = new BetterRandom(); var toppings = _distributedPizzaDbContext.Toppings.ToList(); var orderManager = new OrderManager(toppings, random); order.OrderReferenceId = GetNextSeqAPI(); //order.OrderReferenceId = Guid.NewGuid().ToString(); foreach (var pizza in order.Pizza) { int toppingsTogenerate = random.Next(1, 3); for (var x = 0; x < toppingsTogenerate; x++) { int index = random.Next(toppings.Count); var topping = toppings[index]; pizza.Toppings.Add(topping); } } _distributedPizzaDbContext.Orders.Add(order); _distributedPizzaDbContext.SaveChanges(); IStreamProcessingQueue queue; switch (order.QueueType) { case QueueType.Kafka: queue = new KafkaStreamProcessing(); break; case QueueType.AmazonSQS: queue = new AmazonSQSProcessingQueue(); break; default: queue = new KafkaStreamProcessing(); break; } queue.QueueOrder(order); return(Ok(new OrderResponseDTO { OrderReferenceId = order.OrderReferenceId })); }
private static async Task <int> RunMainAsync() { try { var token = new CancellationTokenSource(); var host = await StartSilo(); Console.WriteLine("Press Enter to terminate..."); var loggerFactory = new LoggerFactory(); loggerFactory.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); NLog.LogManager.LoadConfiguration("nlog.config"); IStreamProcessingQueue kafkaQueue = new KafkaStreamProcessing(); IStreamProcessingQueue amazonQueue = new AmazonSQSProcessingQueue(); Task.Run(() => { kafkaQueue.RetrieveOrders(loggerFactory.CreateLogger("subservice"), null, token.Token); }, token.Token); Task.Run(() => { amazonQueue.RetrieveOrders(loggerFactory.CreateLogger("subservice"), null, token.Token); }, token.Token); Console.ReadLine(); Console.WriteLine("Shutting Down..."); token.Dispose(); await host.StopAsync(); Console.WriteLine("Shut Down"); return(0); } catch (Exception ex) { Console.WriteLine(ex); Console.ReadLine(); return(1); } }