Saga state is the durable record of a saga instance’s current execution position and the application data needed to invoke later steps or return a result. section 10.2.2
A saga state typically holds:
- The current state-machine position, updated as participant responses drive transitions. section 10.2.2
- Request parameters and participant results used as later command arguments or included in the system-command response. section 10.2.2
- A durable database record with a unique ID, so the orchestrator can reload and resume execution after a crash. section 10.2.2
Listing 11.5 CreateOrderSagaState stores the application-specific saga state
public class CreateOrderSagaState {
private Logger logger = LoggerFactory.getLogger(getClass());
private long consumerId;
private long restaurantId;
private DeliveryInformation deliveryInformation;
private List<MenuItemIdAndQuantity> lineItems;
private Long orderId;
private OrderDetails orderDetails;
private long ticketId;
private CreateOrderSagaState() {
}
public CreateOrderSagaState(long consumerId, long restaurantId, #1
DeliveryInformation deliveryInformation,
List<MenuItemIdAndQuantity> lineItems) {
this.consumerId = consumerId;
this.restaurantId = restaurantId;
this.deliveryInformation = deliveryInformation;
this.lineItems = lineItems;
}
// Getters for the fields #2
...
// Methods that update the state #3
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public void setOrderDetails(OrderDetails orderDetails) {
this.orderDetails = orderDetails;
}
public void setTicketId(long ticketId) {
this.ticketId = ticketId;
void handleCreateTicketReply(CreateTicketReply reply) {
logger.debug("getTicketId {}", reply.getTicketId());
setTicketId(reply.getTicketId());
}
The CreateOrderSagaState class illustrates application-specific fields initialized from the request, with getters and update methods used during saga execution. section 11.2.3
