Example #1
0
 private static void SeeIfSandwichIsComplete(SandwichInProgress wip)
 {
     if (wip.IsComplete)
     {
         Console.WriteLine($"### SandwichMaker is done with {wip.CorrelationId}");
         if (!_workInProgress.TryRemove(wip.CorrelationId, out SandwichInProgress temp))
         {
             var id = wip.CorrelationId;
             if (temp != null)
             {
                 id = temp.CorrelationId;
             }
             Console.WriteLine($"### SandwichMaker could NOT remove WIP {id}");
         }
         _queue.SendReply(wip.ReplyTo, wip.CorrelationId, new Messages.SandwichResponse
         {
             Description = wip.GetDescription(),
             Success     = !wip.Failed,
             Error       = wip.GetFailureReason()
         });
         if (wip.Failed)
         {
             Console.WriteLine("### SandwichMaker could NOT make sandwich");
             if (wip.GotMeat.HasValue && wip.GotMeat.Value)
             {
                 _queue.SendMessage("meatbin", wip.CorrelationId, new Messages.MeatBinRequest {
                     Meat = wip.Request.Meat, Returning = true
                 });
             }
             if (wip.GotBread.HasValue && wip.GotBread.Value)
             {
                 _queue.SendMessage("breadbin", wip.CorrelationId, new Messages.BreadBinRequest {
                     Bread = wip.Request.Bread, Returning = true
                 });
             }
             if (wip.GotCheese.HasValue && wip.GotCheese.Value)
             {
                 _queue.SendMessage("cheesebin", wip.CorrelationId, new Messages.CheeseBinRequest {
                     Cheese = wip.Request.Cheese, Returning = true
                 });
             }
             if (wip.GotLettuce.HasValue && wip.GotLettuce.Value)
             {
                 _queue.SendMessage("lettucebin", wip.CorrelationId, new Messages.LettuceBinRequest {
                     Returning = true
                 });
             }
         }
         else
         {
             Console.WriteLine("### SandwichMaker says sandwich is complete");
         }
     }
 }
Example #2
0
        private static void RequestIngredients(BasicDeliverEventArgs ea, string message)
        {
            var request = JsonConvert.DeserializeObject <Messages.SandwichRequest>(message);
            var wip     = new SandwichInProgress
            {
                ReplyTo       = ea.BasicProperties.ReplyTo,
                CorrelationId = ea.BasicProperties.CorrelationId,
                Request       = request
            };

            _workInProgress.Add(ea.BasicProperties.CorrelationId, wip);
            Console.WriteLine($"### Sandwichmaker making {request.Meat} on {request.Bread}{Environment.NewLine}  from {ea.BasicProperties.CorrelationId} at {DateTime.Now}");

            if (!string.IsNullOrEmpty(request.Meat))
            {
                Console.WriteLine($"### Sandwichmaker requesting meat");
                _queue.SendMessage("meatbin", ea.BasicProperties.CorrelationId,
                                   new Messages.MeatBinRequest {
                    Meat = request.Meat
                });
            }
            if (!string.IsNullOrEmpty(request.Bread))
            {
                Console.WriteLine($"### Sandwichmaker requesting bread");
                _queue.SendMessage("breadbin", ea.BasicProperties.CorrelationId,
                                   new Messages.BreadBinRequest {
                    Bread = request.Bread
                });
            }
            if (!string.IsNullOrEmpty(request.Cheese))
            {
                Console.WriteLine($"### Sandwichmaker requesting cheese");
                _queue.SendMessage("cheesebin", ea.BasicProperties.CorrelationId,
                                   new Messages.CheeseBinRequest {
                    Cheese = request.Cheese
                });
            }
            if (request.Lettuce)
            {
                Console.WriteLine($"### Sandwichmaker requesting lettuce");
                _queue.SendMessage("lettucebin", ea.BasicProperties.CorrelationId,
                                   new Messages.LettuceBinRequest());
            }
            SeeIfSandwichIsComplete(wip);
        }
Example #3
0
        private static void RequestIngredients(BasicDeliverEventArgs ea, Messages.SandwichRequest request)
        {
            var wip = new SandwichInProgress
            {
                ReplyTo       = ea.BasicProperties.ReplyTo,
                CorrelationId = ea.BasicProperties.CorrelationId,
                Request       = request
            };

            _workInProgress.TryAdd(ea.BasicProperties.CorrelationId, wip);
            Console.WriteLine($"### Sandwichmaker making {request.Meat} on {request.Bread}{Environment.NewLine}  from {ea.BasicProperties.CorrelationId} at {DateTime.Now}");

            if (!string.IsNullOrEmpty(request.Meat))
            {
                Console.WriteLine($"### Sandwichmaker requesting meat");
                _bus.Publish("MeatBinRequest", ea.BasicProperties.CorrelationId,
                             new Messages.MeatBinRequest {
                    Meat = request.Meat
                });
            }
            if (!string.IsNullOrEmpty(request.Bread))
            {
                Console.WriteLine($"### Sandwichmaker requesting bread");
                _bus.Publish("BreadBinRequest", ea.BasicProperties.CorrelationId,
                             new Messages.BreadBinRequest {
                    Bread = request.Bread
                });
            }
            if (!string.IsNullOrEmpty(request.Cheese))
            {
                Console.WriteLine($"### Sandwichmaker requesting cheese");
                _bus.Publish("CheeseBinRequest", ea.BasicProperties.CorrelationId,
                             new Messages.CheeseBinRequest {
                    Cheese = request.Cheese
                });
            }
            if (request.Lettuce)
            {
                Console.WriteLine($"### Sandwichmaker requesting lettuce");
                _bus.Publish("LettuceBinRequest", ea.BasicProperties.CorrelationId,
                             new Messages.LettuceBinRequest());
            }
            SeeIfSandwichIsComplete(wip);
        }