eventuate-tram / eventuate-tram-sagas

Sagas for microservices
Other
997 stars 225 forks source link

Send one-way commands/notifications to saga participants #76

Open cer opened 2 years ago

cer commented 2 years ago

Requires: https://github.com/eventuate-tram/eventuate-tram-core/issues/174

Motivation is the concurrent execution of compensating transactions and retriable transactions, which are saga steps that by definition cannot fail.

cer commented 2 years ago

Proposed design consists of additional Saga DSL methods:

public class NotificationBasedCreateOrderSaga implements SimpleSaga<NotificationBasedCreateOrderSagaData> {

  private final SagaDefinition<NotificationBasedCreateOrderSagaData> sagaDefinition;

  public NotificationBasedCreateOrderSaga(NotificationBasedCreateOrderSagaSteps steps) {
    this.sagaDefinition =
            step()
                  .invokeLocal(steps::createOrder)
                  .withCompensation(steps::rejectOrder)
            .step()
                  .invokeParticipant(NotificationBasedCreateOrderSagaData::reserveCredit)
                  .withCompensation(NotificationBasedCreateOrderSagaData::releaseCredit)
            .step()
                    .invokeParticipant(NotificationBasedCreateOrderSagaData::reserveInventory)
                    .withCompensationNotification(NotificationBasedCreateOrderSagaData::releaseInventory)
            .step()
                  .invokeLocal(steps::approveOrder)
            .step()
                  .notifyParticipant(NotificationBasedCreateOrderSagaData::fulfillOrder)
            .build();
  }
cer commented 2 years ago

Various remaining TODOs - see // TODO notifications