Skip to content

Commit

Permalink
Preparing message-based OrderFlow sample for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Mar 18, 2024
1 parent b854a51 commit aaa4f90
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,33 @@ namespace Cleipnir.Flows.Sample.Presentation.Examples.OrderFlow.Messaging;

public class OrderFlow : Flow<Order>
{
private readonly MessageBroker _messageBroker;
private MessageBroker MessageBroker { get; }
private ILogger Logger { get; } = Log.Logger.ForContext<OrderFlow>();

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
Expand Down

0 comments on commit aaa4f90

Please sign in to comment.