public Task Handle(IDictionary <string, object> headers, CreateEmployee message) { var msgName = message.GetType().Name; string tenantId = GetTenantId(headers); Console.WriteLine($"Handle {msgName}:\nTenantId: {tenantId}\nBody: {JsonConvert.SerializeObject(message, Formatting.Indented)}"); Console.WriteLine("Press any key to handle the message or press e to simulate exception."); if (Console.ReadKey().Key == ConsoleKey.E) { var msg = $"Cannot handle message: {msgName}"; Console.WriteLine(msg); throw new Exception(msg); } Console.WriteLine("Message is handled"); _bus.Publish(headers, new EmployeeCreatedEvent { Id = message.Id, Name = message.Name, Address = message.Address }); return(Task.FromResult(true)); }
public void Handle(CommandA message) { Console.WriteLine($"Handling command {message.GetType().Name}: {message.ToJsonString()}"); var eventMessage = new EventA { StrProps = $"{message.StrProps}, World!" }; Console.WriteLine($"Publishing event {eventMessage.GetType().Name}: {eventMessage.ToJsonString()}"); _bus.Publish(eventMessage); Console.WriteLine($"Event published!{Environment.NewLine}"); }