コード例 #1
0
        public async Task Consume(ConsumeContext <IFulfillOrder> context)
        {
            _logger.LogInformation($"Fulfilled order {context.Message.OrderId}");

            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            var order = await _orderService.GetOrderAsync(context.Message.OrderId);

            builder.AddActivity("SubmitOrder", QueueNames.GetActivityUri(nameof(SubmitOrderActivity)));

            builder.AddActivity("ReserveProducts", QueueNames.GetActivityUri(nameof(ReserveProductsActivity)), new
            {
                order.OrderItems
            });

            builder.AddActivity("Payment", QueueNames.GetActivityUri(nameof(PaymentActivity)));

            builder.AddActivity("Delivery", QueueNames.GetActivityUri(nameof(DeliveryActivity)));

            builder.AddVariable("CorrelationId", context.Message.CorrelationId);
            builder.AddVariable("OrderId", context.Message.OrderId);

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <IOrderFulfillFaultedEvent>(new { context.Message.OrderId }));

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <IOrderFulfillCompletedEvent>(new { context.Message.OrderId }));

            var routingSlip = builder.Build();
            await context.Execute(routingSlip).ConfigureAwait(false);
        }
コード例 #2
0
        public async Task Consume(ConsumeContext <FullfillOrderMessage> context)
        {
            var Baskets = dbContext.OrderItems.Where(x => x.OrderId == context.Message.OrderId)
                          .Select(p => new { ProductId = p.ProductId, Count = p.Count }).ToList();

            logger.LogInformation($"Fullfilled order {context.Message.OrderId}");
            var builder        = new RoutingSlipBuilder(NewId.NextGuid());
            var submitOrderUrl = QueueNames.GetActivityUri(nameof(SubmitOrderActivity));

            builder.AddActivity("SubmitOrder", submitOrderUrl, new
            {
                context.Message.OrderId
            });;
            builder.AddActivity("Payment", QueueNames.GetActivityUri(nameof(PaymentActivity)), new {
                context.Message.OrderId,
                context.Message.CustomerId,
                context.Message.Credit
            });

            builder.AddActivity("TakeProduct", QueueNames.GetActivityUri(nameof(TakeProductActivity)), new
            {
                context.Message.OrderId,
                Baskets
            });
            builder.AddVariable("OrderId", context.Message.OrderId);
            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Faulted | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <OrderFulfillFaulted>(new { context.Message.OrderId }));

            await builder.AddSubscription(context.SourceAddress,
                                          RoutingSlipEvents.Completed | RoutingSlipEvents.Supplemental,
                                          RoutingSlipEventContents.None, x => x.Send <OrderFullfillCompleted>(new { context.Message.OrderId }));

            var routingSlip = builder.Build();
            await context.Execute(routingSlip).ConfigureAwait(false);
        }