Class Saga.Builder<T>

java.lang.Object
org.acemq.amqp.patterns.Saga.Builder<T>
Enclosing class:
Saga<T>

public static final class Saga.Builder<T> extends Object
Collects the steps of a Saga.
  • Method Details

    • step

      public Saga.Builder<T> step(String stepName, Consumer<T> action)
      Adds a step with no compensation.

      Legitimate for a step that changed nothing, and a mistake for one that did. There is no warning for the second case, because a library cannot tell them apart — which is the argument for writing the compensation first and the action second.

      Parameters:
      stepName - what the step is called
      action - the work
      Returns:
      this builder
    • compensateWith

      public Saga.Builder<T> compensateWith(Consumer<T> compensation)
      Gives the most recently added step something that undoes it.
      Parameters:
      compensation - how to undo the last step
      Returns:
      this builder
    • build

      public Saga<T> build()
      Returns:
      the saga
      Throws:
      IllegalStateException - if it has no steps