Converting the order creation process to use a Saga
In this section, we will be implementing the create order process described earlier in this chapter as an orchestrated saga method. To do so, we will use the SEC from the previous section. We will be doing the following to accomplish this task:
- Updating the modules identified as participants to add new streams, handlers, and commands
- Creating a new module called
cosec
, short for Create-Order-Saga-Execution-Coordinator, that will be responsible for orchestrating the process of creating new orders
Let’s begin by learning how to add commands.
Adding commands to the saga participants
The existing CreateOrder
command for the application in the Order Processing module looks like this:
order, err := h.orders.Load(ctx, cmd.ID)
// 1. authorizeCustomer
err = h.customers.Authorize(ctx, cmd.CustomerID)
if err != nil { return err }
// 2. validatePayment
err = h.payments.Confirm(ctx, cmd.PaymentID)
if err != nil...