public Messages.MeatBinResponse RequestMeat(Messages.MeatBinRequest request) { var response = new Messages.MeatBinResponse(); lock (_lock) { if (request.Returning) { Console.WriteLine($"### Request for {request.GetType().Name} - returned"); _inventory++; } else if (_inventory > 0) { Console.WriteLine($"### Request for {request.GetType().Name} - filled"); _inventory--; response.Success = true; } else { Console.WriteLine($"### Request for {request.GetType().Name} - no inventory"); response.Success = false; } } return(response); }
private static void HandleMessage(BasicDeliverEventArgs ea, Messages.MeatBinRequest request) { var response = new Messages.MeatBinResponse(); lock (_bus) { Thread.Sleep(2000); if (request.Returning) { Console.WriteLine($"### Request for {request.GetType().Name} - returned"); _inventory++; } else if (_inventory > 0) { Console.WriteLine($"### Request for {request.GetType().Name} - filled"); _inventory--; response.Success = true; _bus.Publish("MeatBinResponse", ea.BasicProperties.CorrelationId, response); } else { Console.WriteLine($"### Request for {request.GetType().Name} - no inventory"); response.Success = false; _bus.Publish("MeatBinResponse", ea.BasicProperties.CorrelationId, response); } } }