This is an automated email from the ASF dual-hosted git repository. jianbin pushed a commit to branch docusaurus in repository https://gitbox.apache.org/repos/asf/incubator-seata-website.git
The following commit(s) were added to refs/heads/docusaurus by this push: new 762e021c817 supplemental SAGA annotation usage doc (#964) 762e021c817 is described below commit 762e021c817943bee321a2c1b26cfec127bbc594 Author: funkye <jian...@apache.org> AuthorDate: Tue Apr 29 13:37:07 2025 +0800 supplemental SAGA annotation usage doc (#964) --- .../current/user/mode/saga.md | 34 +++++++++++++++++++++ .../current/user/mode/saga.md | 35 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/i18n/en/docusaurus-plugin-content-docs/current/user/mode/saga.md b/i18n/en/docusaurus-plugin-content-docs/current/user/mode/saga.md index 86c00417b61..4e8101ec5d3 100644 --- a/i18n/en/docusaurus-plugin-content-docs/current/user/mode/saga.md +++ b/i18n/en/docusaurus-plugin-content-docs/current/user/mode/saga.md @@ -915,6 +915,40 @@ Example State Diagram:  +## Basic Usage of Saga Annotation Mode + +Unlike the AT mode which directly uses data source proxies to shield the details of distributed transactions, business developers need to define their own "execution" and "compensation" for saga resources. For example, in the example below: + +```java +@CompensationBusinessAction(name = "DubboSagaActionOne", compensationMethod = "compensation") + public boolean execute(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "param") String param) { +} + +@Override + public boolean compensation(BusinessActionContext actionContext) { +} +``` + +Seata treats a Saga annotation interface as a Resource, also called a Saga annotation Resource. The core annotation in the business interface is `@CompensationBusinessAction`: + +- In the action phase, the business logic of the first phase is executed +- In the compensation phase, when the transaction decides to roll back, the method pointed to by the `compensationMethod` attribute is used to perform custom compensation work. + +Additionally, you can use `BusinessActionContext` to pass query parameters in the transaction context in Saga mode. Properties include: + +- `xid` global transaction id +- `branchId` branch transaction id +- `actionName` branch resource id (resource id) +- `actionContext` business parameters, which can be annotated with `@BusinessActionContextParameter` to indicate parameters that need to be passed. + +After defining the Saga annotation interface, we can start a distributed transaction like in AT mode using `@GlobalTransactional`. + +```java +@GlobalTransactional +public String doTransactionCommit(){ + sagabean.exectue(actionContext....) +} +``` ## FAQ diff --git a/i18n/zh-cn/docusaurus-plugin-content-docs/current/user/mode/saga.md b/i18n/zh-cn/docusaurus-plugin-content-docs/current/user/mode/saga.md index 6f14acd3a21..d55bc767aad 100644 --- a/i18n/zh-cn/docusaurus-plugin-content-docs/current/user/mode/saga.md +++ b/i18n/zh-cn/docusaurus-plugin-content-docs/current/user/mode/saga.md @@ -949,6 +949,41 @@ StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, par  +## Saga注解化模式基本使用 + +区别于在 AT 模式直接使用数据源代理来屏蔽分布式事务细节,业务方需要自行定义 saga 资源的“执行”和“补偿” 。比如在下方的例子中, + +```java +@CompensationBusinessAction(name = "DubboSagaActionOne", compensationMethod = "compensation") + public boolean execute(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "param") String param) { +} + +@Override + public boolean compensation(BusinessActionContext actionContext) { +} +``` + +Seata 会把一个 Saga注解化 接口当成一个 Resource,也叫 Saga annotation Resource。在业务接口中核心的注解是 `@CompensationBusinessAction` + +- action 阶段,执行一阶段的业务逻辑 +- compensation 阶段,当事务觉一回滚(Rollback) 这一阶段使用 `compensationMethod` 属性所指向的方法,来执行自定义 补偿 的工作。 + +其次,可以在 Saga 模式下使用 `BusinessActionContext` 在事务上下文中传递查询参数。如下属性: + +- `xid` 全局事务id +- `branchId` 分支事务id +- `actionName` 分支资源id,(resource id) +- `actionContext` 业务传递的参数,可以通过 `@BusinessActionContextParameter` 来标注需要传递的参数。 + +在定义好 Saga注解化 接口之后,我们可以像 AT 模式一样,通过 `@GlobalTransactional` 开启一个分布式事务。 + +```java +@GlobalTransactional +public String doTransactionCommit(){ + sagabean.exectue(actionContext....) +} +``` + ## FAQ --- --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org