public Task Handle(OrderBilled message, IMessageHandlerContext context)
 {
     log.Info($"Order '{message.OrderId}' has been billed.");
     Data.IsOrderBilled = true;
     CompleteSagaIfBothEventsReceived();
     return(Task.CompletedTask);
 }
        public async Task Consume(ConsumeContext <OrderPlaced> context)
        {
            Thread.Sleep(rnd.Next(0, 3000));
            logger.LogInformation($"Received OrderPlaced, OrderId = {context.Message.OrderId} - Charging credit card...");

            //Make the charging of the card fail randomly to test the retry mechanism
            if (rnd.Next(0, 8) == 0)
            {
                throw new Exception("Credit card charging failed with an exception!");
            }

            Thread.Sleep(rnd.Next(2000, 5000));

            var orderBilled = new OrderBilled
            {
                OrderId       = context.Message.OrderId,
                CorrelationId = context.Message.OrderId,
                BillingDate   = DateTime.Now
            };

            logger.LogInformation($"Credit card successfully charged, order billed at {orderBilled.BillingDate}");

            await context.Publish(orderBilled);

            await Task.CompletedTask;
        }
Ejemplo n.º 3
0
        public void Handle(OrderBilled message)
        {
            Data.OrderId  = message.OrderId;
            Data.IsBilled = true;

            CheckAndPublish();
        }
Ejemplo n.º 4
0
        public async Task Handle(OrderBilled message, IMessageHandlerContext context)
        {
            log.Info($"Received OrderBilled, OrderId = {message.Id}");

            Data.IsOrderBilled = true;
            await ProcessOrder(context);
        }
Ejemplo n.º 5
0
        public Task Handle(OrderBilled message, IMessageHandlerContext context)
        {
            Log.Info($"OrderBilled message received.");

            Data.IsOrderBilled = true;

            return(ProcessOrder(context));
        }
Ejemplo n.º 6
0
        public Task Handle(OrderBilled message, IMessageHandlerContext context)
        {
            log.Info($"Received OrderBilled, OrderId = {message.OrderId}");

            Data.IsOrderBilled = true;

            return(ProcessOrder(context));
        }
Ejemplo n.º 7
0
            public void Handle(OrderBilled message)
            {
                Assert.AreEqual(OrderState.Placed, Data.State);

                Data.State = OrderState.Billed;

                // bus.Send("timeout", new GetBackToMeIfHeDoesntPay{....)
            }
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            log.Info($"Received OrderPlaced, Order Id= {message.OrderId} - Charging credit card...");
            var orderBilled = new OrderBilled {
                OrderId = message.OrderId
            };

            return(context.Publish(orderBilled));
        }
Ejemplo n.º 9
0
        public void Handle(OrderBilled message)
        {
            Data.OrderId = message.OrderId;
            Data.Billed  = true;

            Console.WriteLine($"Received OrderBilled {message.OrderId} - should we ship yet?");

            CheckForCompletion();
        }
Ejemplo n.º 10
0
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            var orderBilled = new OrderBilled
            {
                OrderId = message.OrderId
            };

            return(context.Publish(orderBilled));
        }
Ejemplo n.º 11
0
        public void Handle(OrderBilled message)
        {
            LogManager.GetLogger(typeof(ShippingSaga))
            .Info("Received Order Billed: " + message.OrderId);

            Data.OrderId     = message.OrderId;
            Data.OrderBilled = true;
            CheckIfComplete();
        }
Ejemplo n.º 12
0
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            lock (Console.Out) { Console.BackgroundColor = ConsoleColor.DarkBlue; log.Info($"Received OrderPlaced, OrderId = {message.OrderId}"); Console.ResetColor(); }

            var orderBilled = new OrderBilled {
                OrderId = message.OrderId
            };

            return(context.Publish(orderBilled));
        }
Ejemplo n.º 13
0
        public Task Handle(OrderBilled message, IMessageHandlerContext context)
        {
            Console.WriteLine($"OrderBilled {message.OrderId} - Should we ship now?");
            Data.IsOrderBilled = true;

            //Thread.Sleep(5000);
            //context.Reply()

            return(SendShipOrderCommand(context));
        }
        public void Handle(OrderPlaced message)
        {
            Console.WriteLine($"Received OrderPlaced: {message.OrderId}, publishing OrderBilled");

            var evt = new OrderBilled {
                OrderId = message.OrderId
            };

            Bus.Publish(evt);
        }
Ejemplo n.º 15
0
        public void Timeout(OrderBilled state)
        {
            Data.TotalAmount -= state.Amount;

            if (Data.TotalAmount < 5000d && Data.IsPreferred)
            {
                Data.IsPreferred = false;
                Bus.Publish <CustomerDemoted>(e => e.CustomerId = Data.CustomerId);
            }
        }
Ejemplo n.º 16
0
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            log.Info($"Receive OrderPlaced,SkuName={message.SkuName},OrderCount={message.OrderCount},Charging Credit Card...");
            var orderBilled = new OrderBilled()
            {
                OrderId    = message.OrderId,
                SkuName    = message.SkuName,
                OrderCount = message.OrderCount
            };

            return(context.Publish(orderBilled));
        }
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            log.Info($"Billing has received OrderPlaced, OrderId = {message.OrderId}");

            var orderBilled = new OrderBilled
            {
                OrderId = message.OrderId
            };

            return(context.Publish(orderBilled));

            return(Task.CompletedTask);
        }
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            log.Info($"Received OrderPlaced, OrderId = {message.OrderId} - Charging credit card...");

            var orderBilled = new OrderBilled
            {
                CustomerId = message.CustomerId,
                OrderId    = message.OrderId,
                OrderValue = orderCalculator.GetOrderTotal(message.OrderId)
            };

            return(context.Publish(orderBilled));
        }
Ejemplo n.º 19
0
        public void Handle(OrderBilled message)
        {
            Data.CustomerId = message.CustomerId;

            Data.TotalAmount += message.Amount;

            if (Data.TotalAmount >= 5000d && !Data.IsPreferred)
            {
                Data.IsPreferred = true;
                Bus.Publish <CustomerMadePreferred>(e => e.CustomerId = message.CustomerId);
            }

            RequestTimeout(TimeSpan.FromSeconds(15), message);
        }
Ejemplo n.º 20
0
        public async Task Handle(OrderBilled message, IMessageHandlerContext context)
        {
            Data.CustomerId = message.CustomerId;

            log.Info($"Customer {Data.CustomerId} submitted order of {message.OrderValue}");

            Data.RunningTotal += message.OrderValue;
            await CheckForPreferredStatus(context);

            await RequestTimeout(context, orderExpiryTimeout, new OrderExpired()
            {
                Amount = message.OrderValue
            });
        }
Ejemplo n.º 21
0
        public async Task HandleOrderBilledMessageCorrectly()
        {
            AssumeSagaCanBeMatched();
            var context = new TestableMessageHandlerContext();
            var message = new OrderBilled
            {
                OrderId = _orderId,
            };

            await _target.Handle(message, context);

            await _orderHubMessageDispatcher.Received().SendToGroupAsync(UserId, "StatusUpdated",
                                                                         Arg.Is <OrderStatus>(s => s.OrderId == message.OrderId && s.Status == "Order Billed"));
        }
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            logger.Info($"Received OrderPlaced, OrderId = {message.OrderId}");
            logger.Info("Charching credit card...");
            Thread.Sleep(20 * 1000);

            var orderBilled = new OrderBilled
            {
                OrderId = message.OrderId,
            };

            logger.Info("Credit card charged!");

            return(context.Publish(orderBilled));
        }
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            log.Info($"Received OrderPlaced, OrderId = {message.OrderId} - Charging credit card...");

            // This is normally where some business logic would occur

            // Create event
            var orderBilled = new OrderBilled
            {
                OrderId = message.OrderId
            };

            return(context.Publish(orderBilled));
            // return Task.CompletedTask;
        }
Ejemplo n.º 24
0
        public async Task Handle(OrderBilled message, IMessageHandlerContext context)
        {
            await _dbContext.ShippingLabels.AddAsync(new ShippingLabel
            {
                OrderId   = message.OrderId,
                OrderDate = DateTime.UtcNow
            });

            await _dbContext.SaveChangesAsync();

            await context.Publish <ShippingLabelCreated>(created =>
            {
                created.OrderId = message.OrderId;
            });
        }
        public async Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            Log.Info($"******************** OrderPlaced for order id '{message.OrderId}' ********************");

            // Load the payment method and amount data from the billing database
            // Use Payment Gateway to charge or put hold on the credit card
            Thread.Sleep(4000); // simulate a long running call

            var orderBilled = new OrderBilled
            {
                OrderId = message.OrderId
            };

            await context.Publish(orderBilled);
        }
Ejemplo n.º 26
0
        public Task Handle(OrderPlaced message, IMessageHandlerContext context)
        {
            log.Info($"BILLING - Received PlaceOrder, OrderId = {message.OrderId}\n" +
                     $"Item = {message.Item} - Qty = {message.Quantity}\n" +
                     $"Status = {message.Status} - Charging credit card...\n\n");

            // This is normally where some business logic would occur
            var orderBilled = new OrderBilled
            {
                OrderId  = message.OrderId,
                Item     = message.Item,
                Quantity = message.Quantity,
                Status   = "Credit card charged, order billed."
            };

            return(context.Publish(orderBilled));
        }
Ejemplo n.º 27
0
 public Task Handle(OrderBilled message, IMessageHandlerContext context)
 {
     log.Info($"OrderBilled message received.");
     return(Task.CompletedTask);
 }
Ejemplo n.º 28
0
 public async Task Handle(OrderBilled message, IMessageHandlerContext context)
 {
     Data.Status = "Order Billed";
     await SendStatusUpdate().ConfigureAwait(false);
 }
Ejemplo n.º 29
0
 public void Handle(OrderBilled message)
 {
     this.Data.OrderId     = message.OrderId;
     this.Data.OrderBilled = true;
     HandleOrder();
 }
Ejemplo n.º 30
0
 public Task Handle(OrderBilled message, IMessageHandlerContext context)
 {
     Data.IsOrderBilled = true;
     return(ProcessOrder(context));
 }