public Task Handle(TestCanceled message, IMessageHandlerContext context) { log.Info($"Order #{message.UserId} was cancelled."); //TODO: Possibly publish an OrderCancelled event? MarkAsComplete(); return(Task.CompletedTask); }
static async Task RunLoop(IEndpointInstance endpointInstance) { var lastUser = string.Empty; while (true) { log.Info("Press 'P' to place a new user, 'C' to cancel last user, or 'Q' to quit."); var key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.P: // Instantiate the command var createUserEvent = new UserCreated { // UserId = Guid.NewGuid().ToString() UserId = "123" }; // Send the command log.Info($"Published a new user, UserId = {createUserEvent.UserId}"); await endpointInstance.Publish(createUserEvent) .ConfigureAwait(false); lastUser = createUserEvent.UserId; // Store order identifier to cancel if needed. break; case ConsoleKey.C: var cancelEvent = new TestCanceled { UserId = lastUser }; await endpointInstance.Send(cancelEvent) .ConfigureAwait(false); log.Info($"Sent a correlated message to {cancelEvent.UserId}"); break; case ConsoleKey.Q: return; default: log.Info("Unknown input. Please try again."); break; } } }