private static void HandleMessage(BasicDeliverEventArgs ea, string message) { var request = JsonConvert.DeserializeObject <Messages.LettuceBinRequest>(message); var response = new Messages.LettuceBinResponse(); lock (_queue) { 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; _queue.SendReply(ea.BasicProperties.ReplyTo, ea.BasicProperties.CorrelationId, response); } else { Console.WriteLine($"### Request for {request.GetType().Name} - no inventory"); response.Success = false; _queue.SendReply(ea.BasicProperties.ReplyTo, ea.BasicProperties.CorrelationId, response); } } }
private static void HandleMessage(BasicDeliverEventArgs ea, Messages.LettuceBinRequest request) { var response = new Messages.LettuceBinResponse(); lock (_bus) { 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("LettuceBinResponse", ea.BasicProperties.CorrelationId, response); } else { Console.WriteLine($"### Request for {request.GetType().Name} - no inventory"); response.Success = false; _bus.Publish("LettuceBinResponse", ea.BasicProperties.CorrelationId, response); } } }
private void HandleMessage(Messages.LettuceBinResponse response, SandwichInProgress wip) { lock (wip) { wip.GotLettuce = response.Success; } }
public Messages.LettuceBinResponse RequestLettuce(Messages.LettuceBinRequest request) { var response = new Messages.LettuceBinResponse(); 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 HandleLettuceBinResponse(BasicDeliverEventArgs ea, Messages.LettuceBinResponse response) { Console.WriteLine("### SandwichMaker got lettuce"); if (!string.IsNullOrWhiteSpace(ea.BasicProperties.CorrelationId) && _workInProgress.TryGetValue(ea.BasicProperties.CorrelationId, out SandwichInProgress wip)) { wip.GotLettuce = response.Success; SeeIfSandwichIsComplete(wip); } else { // got lettuce we apparently don't need, so return it Console.WriteLine("### Returning unneeded lettuce"); _bus.Publish("LettuceBinRequest", null, new Messages.LettuceBinRequest { Returning = true }); } }