public async Task <IActionResult> ProcessMealWaiting( [FromServices] RabbitMQConfigurations configurations, [FromServices] ConnectionFactory factory, [FromServices] IConnection connection, [FromServices] IConsumeRabbitMQService consumer) { try{ var result = await consumer.ProcessQueue("Meal - waiting"); if (result != null) { using (var channel = connection.CreateModel()) { var queue = channel.QueueDeclare(queue: "Command Queue", durable: false, exclusive: false, autoDelete: false, arguments: null); //RabbitMQExtensions.GetAllMessages(queue ,configurations, "Side Dish - waiting"); string message = JsonConvert.SerializeObject(result); var body = Encoding.UTF8.GetBytes(message); channel.BasicPublish(exchange: "", routingKey: "Meal - preparing", basicProperties: null, body: body); //channel.WaitForConfirmsOrDie(new TimeSpan(0, 0, 5)); //Dictionary<string, string> headers = new Dictionary<string, string>(); var properties = channel.CreateBasicProperties(); properties.Persistent = false; Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("Command", "MealPreparing"); properties.Headers = dictionary; channel.BasicPublish(exchange: "", routingKey: "Command Queue", basicProperties: properties, body: body); //channel.WaitForConfirmsOrDie(new TimeSpan(0, 0, 5)); } } return(Ok()); } catch (Exception ex) { return(BadRequest()); } }
public IActionResult ShowQueueItem( [FromServices] RabbitMQConfigurations configurations, [FromServices] ConnectionFactory factory, [FromServices] IConnection connection, [FromServices] IConsumeRabbitMQService consumer, string kitchenAreaName, string status) { try { using (var channel = connection.CreateModel()) { var queue = channel.QueueDeclare(queue: kitchenAreaName + " - " + status, durable: false, exclusive: false, autoDelete: false, arguments: null); var result = RabbitMQExtensions.GetAllMessages(queue, configurations, queue.QueueName); if (result == null) { return(BadRequest()); } return(Ok(result)); } } catch (Exception ex) { return(BadRequest()); } }