add saga init dsc
This commit is contained in:
45
saga/README.md
Normal file
45
saga/README.md
Normal file
@ -0,0 +1,45 @@
|
||||
---
|
||||
layout: pattern
|
||||
title: Saga
|
||||
folder: Communication
|
||||
permalink: /patterns/saga/
|
||||
categories: Behavioral
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Expert
|
||||
- Idiom
|
||||
- Distributed communication
|
||||
---
|
||||
|
||||
## Also known as
|
||||
This pattern has a similar goal with two-phase commit (XA transaction)
|
||||
|
||||
## Intent
|
||||
This pattern is used in distributed services to perform a group of operations atomically.
|
||||
This is an analog of transaction in a database but in terms of microservices architecture this is performed in a distributed environment
|
||||
|
||||
## Explanation
|
||||
A saga is a sequence of local transactions in a certain context. If one transaction fails for some reason,
|
||||
the saga executes compensating transactions(rollbacks) to undo the impact of the preceding transactions.
|
||||
There are two types of Saga:
|
||||
|
||||
- Choreography-Based Saga.
|
||||
In this approach, there is no central orchestrator.
|
||||
Each service participating in the Saga performs their transaction and publish events.
|
||||
The other services act upon those events and perform their transactions.
|
||||
Also, they may or not publish other events based on the situation.
|
||||
|
||||
- Orchestration-Based Saga
|
||||
In this approach, there is a Saga orchestrator that manages all the transactions and directs
|
||||
the participant services to execute local transactions based on events.
|
||||
This orchestrator can also be though of as a Saga Manager.
|
||||
|
||||
## Applicability
|
||||
Use the Saga pattern, if:
|
||||
- you need to perform a group of operations related to different microservices atomically
|
||||
- you need to rollback changes in different places in case of failure one of the operation
|
||||
- you need to take care of data consistency in different places including different databases
|
||||
- you can not use 2PC(two phase commit)
|
||||
|
||||
## Credits
|
||||
- [pattern description](https://microservices.io/patterns/data/saga.html)
|
44
saga/pom.xml
Normal file
44
saga/pom.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright © 2014-2019 Ilkka Seppälä
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<version>1.22.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>saga</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Reference in New Issue
Block a user