示例#1
0
        public void Handle(OrderCreated message)
        {
            Console.WriteLine("Received order created event: OrderId: {0}", message.OrderId);
            var cardDetails  = Database.GetCardDetailsFor(message.UserId);
            var confirmation = PaymentProvider.ChargeCreditCard(cardDetails, message.Amount);
            var command      = new RecordPaymentAttempt
            {
                OrderId = message.OrderId,
                Status  = confirmation.Status
            };

            Bus.SendLocal(command);
        }
        public async Task Consume(ConsumeContext <OrderCreated> context)
        {
            var message = context.Message;

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("\n--->> Received order created event: OrderId: {0}\n", message.OrderId);
            Console.ResetColor();

            var cardDetails  = Database.GetCardDetailsFor(message.UserId);
            var confirmation = PaymentProvider.ChargeCreditCard(cardDetails, message.Amount);

            // NOTE_JBOY: Chris Patterson prefers not use .Send(), but .Publish() instead - https://stackoverflow.com/questions/62713786/masstransit-endpointconvention-azure-service-bus/62714778#62714778
            await context.Publish <RecordPaymentAttempt>(new
            {
                OrderId = message.OrderId,
                Status  = confirmation.Status
            });
        }