public static void Process(Messages.Message <Messages.Orders.Order> message) { AValidation validation = new Validation(); bool success = validation.Process(message.Body); if (success == true) { SendMessageToNextValidation(message); } else { Messages.Header header = new Messages.Header() { Date = message.Header.Date, Success = false, RoutingSlip = null }; string messageConcatenated = ""; foreach (var notification in validation.Notifications) { messageConcatenated += notification.Message; } Messages.Response.Response response = new Messages.Response.Response() { CustomerId = message.Body.CustomerId, OrderId = message.Body.OrderId, Message = messageConcatenated }; Messages.Message <Messages.Response.Response> responseMessage = new Messages.Message <Messages.Response.Response>(header, response); SendResponseMessage(responseMessage); } }
static void SendMessageToNextValidation(Messages.Message <Messages.Orders.Order> message) { if (message.Header.RoutingSlip.Forward != null || message.Header.RoutingSlip.Forward.Count != 0) { if (message.Header.RoutingSlip.Forward[0] != null) { Console.WriteLine($"Foward to {message.Header.RoutingSlip.Forward[0]}"); string forward = message.Header.RoutingSlip.Forward[0]; message.Header.RoutingSlip.Forward.RemoveAt(0); using (IModel channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange: routerExchangeName, type: ExchangeType.Direct); byte[] body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); channel.BasicPublish(exchange: routerExchangeName, routingKey: forward, basicProperties: null, body: body); } Console.WriteLine($"OrderId: {message.Body.OrderId} send forward to {forward}."); } } else { Messages.Header header = new Messages.Header() { Date = message.Header.Date, Success = true, RoutingSlip = null }; Messages.Response.Response response = new Messages.Response.Response() { CustomerId = message.Body.CustomerId, OrderId = message.Body.OrderId, Message = "" }; Messages.Message <Messages.Response.Response> responseMessage = new Messages.Message <Messages.Response.Response>(header, response); SendResponseMessage(responseMessage); } }