docs: Saga explanation (#2962)

* docs: update cqrs pattern name

* docs: add saga docs
This commit is contained in:
Ilkka Seppälä
2024-05-19 16:04:44 +03:00
committed by GitHub
parent 3297eb42a0
commit 25d12fdc06
7 changed files with 142 additions and 65 deletions
@@ -27,6 +27,8 @@ package com.iluwatar.saga.choreography;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
/**
* Saga representation. Saga consists of chapters. Every ChoreographyChapter is executed a certain
@@ -154,37 +156,19 @@ public class Saga {
* outcoming parameter).
*/
public static class Chapter {
@Getter
private final String name;
@Setter
private ChapterResult result;
@Getter
@Setter
private Object inValue;
public Chapter(String name) {
this.name = name;
this.result = ChapterResult.INIT;
}
public Object getInValue() {
return inValue;
}
public void setInValue(Object object) {
this.inValue = object;
}
public String getName() {
return name;
}
/**
* set result.
*
* @param result {@link ChapterResult}
*/
public void setResult(ChapterResult result) {
this.result = result;
}
/**
* the result for chapter is good.
*
@@ -45,7 +45,7 @@ public class WithdrawMoneyService extends Service {
if (inValue.equals("bad_order")) {
LOGGER.info("The chapter '{}' has been started. But the exception has been raised."
+ "The rollback is about to start",
getName(), inValue);
getName());
saga.setCurrentStatus(Saga.ChapterResult.ROLLBACK);
return saga;
}
@@ -24,19 +24,18 @@
*/
package com.iluwatar.saga.orchestration;
import lombok.Getter;
/**
* Executing result for chapter.
*
* @param <K> incoming value
*/
public class ChapterResult<K> {
@Getter
private final K value;
private final State state;
public K getValue() {
return value;
}
ChapterResult(K value, State state) {
this.value = value;
this.state = state;
@@ -26,6 +26,8 @@ package com.iluwatar.saga.orchestration;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Saga representation. Saga consists of chapters. Every ChoreographyChapter is executed by a
@@ -70,15 +72,9 @@ public class Saga {
/**
* class represents chapter name.
*/
@AllArgsConstructor
@Getter
public static class Chapter {
String name;
public Chapter(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}
@@ -38,7 +38,7 @@ public class WithdrawMoneyService extends Service<String> {
if (value.equals("bad_order") || value.equals("crashed_order")) {
LOGGER.info("The chapter '{}' has been started. But the exception has been raised."
+ "The rollback is about to start",
getName(), value);
getName());
return ChapterResult.failure(value);
}
return super.process(value);