Skip to content

Commit

Permalink
Merge 2cc1cfe into b30d8aa
Browse files Browse the repository at this point in the history
  • Loading branch information
WillemJiang committed Jan 2, 2019
2 parents b30d8aa + 2cc1cfe commit a51a9d3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
25 changes: 24 additions & 1 deletion docs/user_guide.md
Expand Up @@ -51,13 +51,23 @@ After executing either one of the above command, you will find alpha server's ex
<version>${pack.version}</version>
</dependency>
```
**Note**: Please change the `${pack.version}` to the actual version. Since 0.3.0 we update the package name of
**Note**: Please change the `${pack.version}` to the actual version.

**Migration Note**:Since 0.3.0 we rename the project repository name from saga to pack. Please update the group id and package name if you migrate your application from saga 0.2.x to pack 0.3.0.

| name | 0.2.x | 0.3.x |
| ---- | ---- | ---- |
| groupId | org.apache.servicecomb.saga | org.apache.servicecomb.pack |
| Package Name | org.apache.servicecomb.saga | org.apache.servicecomb.pack |

### Saga Support
Add saga annotations and corresponding compensation methods
Take a transfer money application as an example:
1. add `@EnableOmega` at application entry to initialize omega configurations and connect to alpha
```java
import org.apache.servicecomb.pack.omega.spring.EnableOmega;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableOmega
public class Application {
Expand All @@ -69,6 +79,8 @@ Take a transfer money application as an example:

2. add `@SagaStart` at the starting point of the global transaction
```java
import org.apache.servicecomb.pack.omega.context.annotations.SagaStart;

@SagaStart(timeout=10)
public boolean transferMoney(String from, String to, int amount) {
transferOut(from, amount);
Expand All @@ -79,6 +91,9 @@ Take a transfer money application as an example:

3. add `@Compensable` at the sub-transaction and specify its corresponding compensation method
```java
import javax.transaction.Transactional;
import org.apache.servicecomb.pack.omega.transaction.annotations.Compensable;

@Compensable(timeout=5, compensationMethod="cancel")
@Transactional
public boolean transferOut(String from, int amount) {
Expand Down Expand Up @@ -107,6 +122,9 @@ Add TCC annotations and corresponding confirm and cancel methods
Take a transfer money application as an example:
1. add `@EnableOmega` at application entry to initialize omega configurations and connect to alpha
```java
import org.apache.servicecomb.pack.omega.spring.EnableOmega;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableOmega
public class Application {
Expand All @@ -118,6 +136,8 @@ Add TCC annotations and corresponding confirm and cancel methods

2. add `@TccStart` at the starting point of the global transaction
```java
import org.apache.servicecomb.pack.omega.context.annotations.TccStart;

@TccStart
public boolean transferMoney(String from, String to, int amount) {
transferOut(from, amount);
Expand All @@ -128,6 +148,9 @@ Add TCC annotations and corresponding confirm and cancel methods

3. add `@Participate` at the sub-transaction and specify its corresponding compensation method
```java
import javax.transaction.Transactional;
import org.apache.servicecomb.pack.omega.transaction.annotations.Participate;

@Participate(confirmMethod = "confirm", cancelMethod = "cancel")
@Transactional
public void transferOut(String from, int amount) {
Expand Down
24 changes: 24 additions & 0 deletions docs/user_guide_zh.md
Expand Up @@ -52,12 +52,23 @@ Saga可通过以下任一方式进行构建:
</dependency>
```
**注意**: 请将`${pack.version}`更改为实际的版本号。
**版本迁移提示**: 从0.3.0 开始,整个项目的代码库名由servicecomb-saga改名为servicecomb-pack, 与此同时我们也更新了对应发布包的组名以及相关包名。
如果你的项目是从saga 0.2.x 迁移过来,请按照下表所示进行修改。

| name | 0.2.x | 0.3.x |
| ---- | ---- | ---- |
| groupId | org.apache.servicecomb.saga | org.apache.servicecomb.pack |
| Package Name | org.apache.servicecomb.saga | org.apache.servicecomb.pack |


### Saga 支持
添加Saga的注解及相应的补偿方法
以一个转账应用为例:
1. 在应用入口添加 `@EnableOmega` 的注解来初始化omega的配置并与alpha建立连接。
```java
import org.apache.servicecomb.pack.omega.spring.EnableOmega;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableOmega
public class Application {
Expand All @@ -69,6 +80,8 @@ Saga可通过以下任一方式进行构建:

2. 在全局事务的起点添加 `@SagaStart` 的注解。
```java
import org.apache.servicecomb.pack.omega.context.annotations.SagaStart;

@SagaStart(timeout=10)
public boolean transferMoney(String from, String to, int amount) {
transferOut(from, amount);
Expand All @@ -79,6 +92,9 @@ Saga可通过以下任一方式进行构建:

3. 在子事务处添加 `@Compensable` 的注解并指明其对应的补偿方法。
```java
import javax.transaction.Transactional;
import org.apache.servicecomb.pack.omega.transaction.annotations.Compensable;

@Compensable(timeout=5, compensationMethod="cancel")
@Transactional
public boolean transferOut(String from, int amount) {
Expand Down Expand Up @@ -106,6 +122,9 @@ Saga可通过以下任一方式进行构建:
以一个转账应用为例:
1. 在应用入口添加 `@EnableOmega` 的注解来初始化omega的配置并与alpha建立连接。
```java
import org.apache.servicecomb.pack.omega.spring.EnableOmega;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableOmega
public class Application {
Expand All @@ -117,6 +136,8 @@ Saga可通过以下任一方式进行构建:

2. 在全局事务的起点添加 `@TccStart` 的注解。
```java
import org.apache.servicecomb.pack.omega.context.annotations.TccStart;

@TccStart
public boolean transferMoney(String from, String to, int amount) {
transferOut(from, amount);
Expand All @@ -127,6 +148,9 @@ Saga可通过以下任一方式进行构建:

3. 在子事务尝试方法处添加 `@Participate` 的注解并指明其对应的执行以及补偿方法名,
```java
import javax.transaction.Transactional;
import org.apache.servicecomb.pack.omega.transaction.annotations.Participate;

@Participate(confirmMethod = "confirm", cancelMethod = "cancel")
@Transactional
public void transferOut(String from, int amount) {
Expand Down

0 comments on commit a51a9d3

Please sign in to comment.