public final class SagaDSL extends Object
To build a saga:
SagaBuilder
with createBuilder()
SagaBuilder
to add saga actions. Each addAction()
creates a SubSaga
.andThen()
.
Defining dependencies between actions creates subsagas consisting of multiple actions. Dependencies can be defined between these subsagas.build()
. Any SubSaga
s that are not dependent on each other can be executed in parallel.For example:
import io.simplesource.saga.client.dsl.SagaDSL;
import static io.simplesource.saga.client.dsl.SagaDSL;
SagaBuilder<A> sagaBuilder = SagaDSL.createBuilder();
SubSaga<A> actionA = sagaBuilder.addAction(actionIdA, actionCommandA, undoCommandA);
SubSaga<A> actionB = sagaBuilder.addAction(actionIdB, actionB, undoActionB);
SubSaga<A> actionC = sagaBuilder.addAction(actionIdC, actionC, undoActionC);
inParallel(actionA, actionB).andThen(actionC);
Result<SagaError, Saga<A>> sagaBuildResult = sagaBuilder.build();
The andThen
operator is associative. This means that the following are equivalent:
a.andThen(b.andThen(c))
and
a.andThen(b).andThen(c)
Modifier and Type | Class and Description |
---|---|
static class |
SagaDSL.SagaBuilder<A>
A SagaBuilder is used to add actions by creating a subsaga consisting of a single action, and to build the saga once the definition steps are complete.
|
static class |
SagaDSL.SubSaga<A>
A
Subsaga is a subset of a saga consisting of one or more action, with dependencies defined between them. |
Constructor and Description |
---|
SagaDSL() |
Modifier and Type | Method and Description |
---|---|
static <A> SagaDSL.SagaBuilder<A> |
createBuilder()
Creates a
SagaBuilder |
static <A> SagaDSL.SubSaga<A> |
inParallel(Collection<SagaDSL.SubSaga<A>> subSagas)
Creates a subsagas consisting of a collection of subsagas executing in parallel.
|
static <A> SagaDSL.SubSaga<A> |
inParallel(SagaDSL.SubSaga<A> subSaga,
SagaDSL.SubSaga<A>... subSagas)
Creates a subsagas consisting of one or more subsagas executing in parallel.
|
static <A> SagaDSL.SubSaga<A> |
inSeries(Iterable<SagaDSL.SubSaga<A>> subSagas)
Creates a subsagas consisting of an ordered collection of subsagas executing in series.
|
static <A> SagaDSL.SubSaga<A> |
inSeries(SagaDSL.SubSaga<A> subSaga,
SagaDSL.SubSaga<A>... subSagas)
Creates a subsagas consisting of one or more subsagas executing in series.
|
public static <A> SagaDSL.SagaBuilder<A> createBuilder()
SagaBuilder
A
- a representation of an action command that is shared across all actions in the saga. This is typically a generic type, such as Json, or if using Avro serialization, SpecificRecord or GenericRecordpublic static <A> SagaDSL.SubSaga<A> inParallel(SagaDSL.SubSaga<A> subSaga, SagaDSL.SubSaga<A>... subSagas)
A
- a representation of an action command that is shared across all actions in the saga. This is typically a generic type, such as Json, or if using Avro serialization, SpecificRecord or GenericRecordsubSagas
- a sub sagasubSagas
- the sub sagaspublic static <A> SagaDSL.SubSaga<A> inSeries(SagaDSL.SubSaga<A> subSaga, SagaDSL.SubSaga<A>... subSagas)
A
- a representation of an action command that is shared across all actions in the saga. This is typically a generic type, such as Json, or if using Avro serialization, SpecificRecord or GenericRecordsubSagas
- the sub sagaspublic static <A> SagaDSL.SubSaga<A> inParallel(Collection<SagaDSL.SubSaga<A>> subSagas)
A
- a representation of an action command that is shared across all actions in the saga. This is typically a generic type, such as Json, or if using Avro serialization, SpecificRecord or GenericRecordsubSagas
- A collection of subsagaspublic static <A> SagaDSL.SubSaga<A> inSeries(Iterable<SagaDSL.SubSaga<A>> subSagas)
A
- a representation of an action command that is shared across all actions in the saga. This is typically a generic type, such as Json, or if using Avro serialization, SpecificRecord or GenericRecordsubSagas
- A collection of subsagasCopyright © 2019. All rights reserved.