Example #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);
        }
Example #3
0
        private Task RequestCheese(SandwichInProgress wip, Messages.CheeseBinRequest request)
        {
            if (string.IsNullOrEmpty(wip.Request.Cheese))
            {
                return(Task.CompletedTask);
            }

            return(_retryPolicy.ExecuteAndCapture <Task>(() =>
                                                         _httpClient.PutAsJsonAsync(
                                                             _config["Cheeseservice:url"] + "/api/Cheesebin",
                                                             request).
                                                         ContinueWith(async(e) => HandleMessage(await e.Result.Content.ReadAsAsync <Messages.CheeseBinResponse>(), wip))
                                                         ).Result);
        }