From aaa4f90f66fff62b18faffb2c810d7fe01b56fb4 Mon Sep 17 00:00:00 2001 From: stidsborg Date: Mon, 18 Mar 2024 09:48:54 +0100 Subject: [PATCH] Preparing message-based OrderFlow sample for presentation --- .../Examples/OrderFlow/Messaging/OrderFlow.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/OrderFlow.cs b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/OrderFlow.cs index 440231f..0e0ab80 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/OrderFlow.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/OrderFlow.cs @@ -5,15 +5,33 @@ namespace Cleipnir.Flows.Sample.Presentation.Examples.OrderFlow.Messaging; public class OrderFlow : Flow { - private readonly MessageBroker _messageBroker; + private MessageBroker MessageBroker { get; } private ILogger Logger { get; } = Log.Logger.ForContext(); - public OrderFlow(MessageBroker messageBroker) => _messageBroker = messageBroker; + public OrderFlow(MessageBroker messageBroker) => MessageBroker = messageBroker; public override async Task Run(Order order) { Logger.Information($"Processing of order '{order.OrderId}' started"); + Logger.Information($"Processing of order '{order.OrderId}' started"); + + var transactionId = await Effect.CreateOrGet("TransactionId", Guid.NewGuid()); + + await MessageBroker.Send(new ReserveFunds(order.OrderId, order.TotalPrice, transactionId, order.CustomerId)); + //wait for ReserveFunds + + await MessageBroker.Send(new ShipProducts(order.OrderId, order.CustomerId, order.ProductIds)); + //wait for ProductsShipped + + await MessageBroker.Send(new CaptureFunds(order.OrderId, order.CustomerId, transactionId)); + //wait for FundsCaptured + + await MessageBroker.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId)); + //wait for order OrderConfirmationEmailSent + + Logger.Information($"Processing of order '{order.OrderId}' completed"); + /* Command types: - ReserveFunds