Beispiel #1
0
        private static void HandleMessage(BasicDeliverEventArgs ea, Messages.BreadBinRequest request)
        {
            var response = new Messages.BreadBinResponse();

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

            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);
        }
Beispiel #3
0
        private Task RequestBread(SandwichInProgress wip, Messages.BreadBinRequest request)
        {
            if (string.IsNullOrEmpty(wip.Request.Bread))
            {
                return(Task.CompletedTask);
            }

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