Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
 private void HandleMessage(Messages.LettuceBinResponse response, SandwichInProgress wip)
 {
     lock (wip)
     {
         wip.GotLettuce = response.Success;
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 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
         });
     }
 }