public IActionResult Index() { int n = 1; while (n < 6) { try{ var command = new StartBatchCommand { BatchId = DateTime.Now.Second, StartDate = DateTime.Now }; var factory = new ConnectionFactory() { HostName = "rabbit", Port = 5672 }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var properties = channel.CreateBasicProperties(); channel.QueueDeclare(queue: "StartBatchCommand", durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueDeclare(queue: "InitializedMessage", durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueDeclare(queue: "CalculatedMessage", durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueDeclare(queue: "PdfGeneratedMessage", durable: false, exclusive: false, autoDelete: false, arguments: null); n = 7; return(View()); } }catch (Exception e) { ViewBag.Error = e.Message; n++; return(View("NotHealthy")); } } return(View("NotHealthy")); }
public IActionResult Run() { try{ var command = new StartBatchCommand { BatchId = DateTime.Now.Second, StartDate = DateTime.Now }; var factory = new ConnectionFactory() { HostName = "rabbit", Port = 5672 }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var properties = channel.CreateBasicProperties(); channel.QueueDeclare(queue: "StartBatchCommand", durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueDeclare(queue: "InitializedMessage", durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueDeclare(queue: "CalculatedMessage", durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueDeclare(queue: "PdfGeneratedMessage", durable: false, exclusive: false, autoDelete: false, arguments: null); var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(command)); channel.BasicPublish(exchange: "", routingKey: "StartBatchCommand", basicProperties: properties, body: body); Console.WriteLine("Sent StartBatchCommand"); } return(View("Success")); }catch (Exception e) { Console.WriteLine($"Error sending StartBatchCommand {e.Message}"); return(View("Error")); } }