public ActionResult Query(string queryName, string json) { var queryInstance = CqrsHelper.GetQueryInstance(queryName, json); var result = CqrsHelper.ExecuteQuery(queryInstance); return(Json(result, JsonRequestBehavior.AllowGet)); }
public ActionResult Query(string queryName, string json) { var queryInstance = CqrsHelper.GetQueryInstance(queryName, json); // отправить запрос, получить ответ var res = _esbMessageService.SendAndGetResult( new EsbMessage( queryInstance.ServiceName, queryName, JsonConvert.SerializeObject(queryInstance) )); if (res.IsError) { throw new Exception(res.ErrorText); } return(Content(res.Body, "application/json")); }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: ServiceName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body; var rk = ea.RoutingKey; var message = JsonConvert.DeserializeObject <EsbMessageBody>(Encoding.UTF8.GetString(body)); Console.WriteLine(" [x] Received {0} routing key: {1} reply to: {2} corrId: {3}", message.Body, rk, ea.BasicProperties.ReplyTo, ea.BasicProperties.CorrelationId); if (message.Header.EndsWith("Command")) { var commandInstance = CqrsHelper.GetCommandInstance(message.Header, message.Body); CqrsHelper.ExcecuteCommand(commandInstance); } else if (message.Header.EndsWith("Query")) { var queryInstance = CqrsHelper.GetQueryInstance(message.Header, message.Body); var result = CqrsHelper.ExecuteQuery(queryInstance); if (ea.BasicProperties.ReplyTo != null) { var replyProps = channel.CreateBasicProperties(); replyProps.CorrelationId = ea.BasicProperties.CorrelationId; channel.BasicPublish("", ea.BasicProperties.ReplyTo, replyProps, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(result))); } } else { Console.WriteLine("Неопознанное сообщение: " + message.Header); return; } channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); }; channel.BasicConsume( queue: ServiceName, noAck: false, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } }