public Task Handle(PlaceOrder message, IMessageHandlerContext context) { _processingCount++; _log.Info($"RECV {nameof(PlaceOrder)} [{_processingCount}], {nameof(message.Id)}: {message.Id}"); var orderPlaced = new OrderPlaced { OrderId = message.Id, IsGrouped = message.IsGrouped }; var task = context.Publish(orderPlaced); _log.Info($"POST {nameof(OrderPlaced)} [{_processingCount}], {nameof(orderPlaced.OrderId)}: {orderPlaced.OrderId}"); if (message.IsGrouped != _groupItems) { // Grouping completed. if (_groupItems) { _groupItems = false; _log.Info(_sw.LogTimeToMessage("GROUP COMPLETE ")); } // Grouping started; else { _groupItems = true; _sw = StopwatchExtensions.CreateStartSW(); } } return(task); }
public async Task Consume(ConsumeContext <IPlaceOrderCommand> context) { _processingCount++; // TODO: Need to determine MassTransit logging services and not use console. await Console.Out.WriteLineAsync($"RECV {nameof(IPlaceOrderCommand)} [{_processingCount}], {nameof(context.Message.Id)}: {context.Message.Id}"); //notify subscribers that a order is registered await context.Publish <IOrderPlacedEvent>(new { OrderId = context.Message.Id, context.Message.IsGrouped }); await Console.Out.WriteLineAsync($"POST {nameof(IOrderPlacedEvent)} [{_processingCount}], {nameof(IOrderPlacedEvent.OrderId)}: {context.Message.Id}"); if (context.Message.IsGrouped != _groupItems) { // Grouping completed. if (_groupItems) { _groupItems = false; _sw.LogTimeToConsole("GROUP COMPLETE "); } // Grouping started; else { _groupItems = true; _sw = StopwatchExtensions.CreateStartSW(); } } }
public async Task Consume(ConsumeContext <IOrderPlacedEvent> context) { _processingCount++; // TODO: Need to determine MassTransit logging services and not use console. await Console.Out.WriteLineAsync($"RECV {nameof(IOrderPlacedEvent)} [{_processingCount}], {nameof(context.Message.OrderId)}: {context.Message.OrderId}"); if (context.Message.IsGrouped != _groupItems) { // Grouping completed. if (_groupItems) { _groupItems = false; _sw.LogTimeToConsole("GROUP COMPLETE "); } // Grouping started; else { _groupItems = true; _sw = StopwatchExtensions.CreateStartSW(); } } }
private static async Task SendOrders(IMessageSession endpointInstance) { Console.WriteLine("Press enter to send 1 message or a number + enter to send X messages."); Console.WriteLine("Type 'exit' to exit"); Console.WriteLine(); while (true) { var keys = Console.ReadLine(); int count; if (keys == "") { count = 1; } else if (string.Compare(keys, "exit", StringComparison.InvariantCultureIgnoreCase) == 0) { return; } else { if (!int.TryParse(keys, out count)) { await Console.Out.WriteLineAsync("Keys Not Recognized."); } } var sw = StopwatchExtensions.CreateStartSW(); for (var inc = 0; inc < count; inc++) { await SendOrder(endpointInstance, count > 1 && inc != count - 1); } if (count > 1) { await sw.LogTimeToConsoleAsync($"GROUP COMPLETE "); } } }
public Task Handle(OrderPlaced message, IMessageHandlerContext context) { _processingCount++; _log.Info($"RECV {nameof(OrderPlaced)} [{_processingCount}], {nameof(message.OrderId)}: {message.OrderId}"); if (message.IsGrouped != _groupItems) { // Grouping completed. if (_groupItems) { _groupItems = false; _log.Info(_sw.LogTimeToMessage("GROUP COMPLETE ")); } // Grouping started; else { _groupItems = true; _sw = StopwatchExtensions.CreateStartSW(); } } return(Task.CompletedTask); }