Ejemplo n.º 1
0
        private static void HandleMessage(BasicDeliverEventArgs ea, Messages.CheeseBinRequest request)
        {
            var response = new Messages.CheeseBinResponse();

            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("CheeseBinResponse", ea.BasicProperties.CorrelationId, response);
                }
                else
                {
                    Console.WriteLine($"### Request for {request.GetType().Name} - no inventory");
                    response.Success = false;
                    _bus.Publish("CheeseBinResponse", ea.BasicProperties.CorrelationId, response);
                }
            }
        }
        public Messages.CheeseBinResponse RequestCheese(Messages.CheeseBinRequest request)
        {
            var response = new Messages.CheeseBinResponse();

            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);
        }