8 changed files with 47 additions and 68 deletions
@ -1,42 +0,0 @@ |
|||
### 轻量级分布式事务管理服务 |
|||
跨语言--语言无关,基于http协议 |
|||
支持xa、tcc、saga |
|||
## 快速开始 |
|||
dtm依赖于mysql |
|||
使用已有的mysql: |
|||
参考conf.yml.sample将mysql信息填写到conf.yml |
|||
或者通过docker安装mysql |
|||
docker-compose up -f docker-compose.mysql.yml |
|||
启动并运行saga示例 |
|||
go run app/main.go |
|||
|
|||
场景描述: |
|||
假设您实现了一个转账功能,分为两个微服务:转入、转出 |
|||
转出:服务地址为 http://example.com/api/busi_saga/transOut?gid=xxx POST 参数为 {"uid": 2, "amount":30} |
|||
转入:服务地址为 http://example.com/api/busi_saga/transIn?gid=xxx POST 参数为 {"uid": 1, "amount":30} |
|||
在saga模式下,有对应的补偿微服务 |
|||
转出:服务地址为 http://example.com/api/busi_saga/transOutCompensate?gid=xxx POST 参数为 {"uid": 2, "amount":30} |
|||
转入:服务地址为 http://example.com/api/busi_saga/transInCompensate?gid=xxx POST 参数为 {"uid": 1, "amount":30} |
|||
HTTP协议方式 |
|||
curl -d '{"gid":"xxx","trans_type":"saga","steps":[{"action":"http://example.com/api/busi_saga/TransOut","compensate":"http://example.com/api/busi_saga/TransOutCompensate","data":"{\"amount\":30}"},{"action":"http://localhost:8081/api/busi_saga/TransIn","compensate":"http://localhost:8081/api/busi_saga/TransInCompensate","data":"{\"amount\":30}"}]}' 8.140.124.252/api/dtm/commit |
|||
此请求向dtm提交了一个saga事务,dtm会按照saga模式,请求transIn/transOut,并且在出错情况下,保证抵用相关的补偿api |
|||
go客户端方式 |
|||
// 事务参与者的服务地址 |
|||
const startBusiPort = 8084 |
|||
const startBusiApi = "/api/busi_start" |
|||
|
|||
var startBusi = fmt.Sprintf("http://localhost:%d%s", startBusiPort, startBusiApi) |
|||
err := dtm.SagaNew(DtmServer, gid).Add(startBusi+"/TransOut", startBusi+"/TransOutCompensate", &gin.H{ |
|||
"amount": 30, |
|||
"uid": 2, |
|||
}).Add(startBusi+"/TransIn", startBusi+"/TransInCompensate", &gin.H{ |
|||
"amount": 30, |
|||
"uid": 1 |
|||
}).Commit() |
|||
|
|||
本地启动方式 |
|||
需要安装docker,和docker-compose |
|||
curl localhost:8080/api/initMysql |
|||
go run examples/app/main saga |
|||
|
|||
其他 |
|||
@ -0,0 +1,6 @@ |
|||
# a lightweight distributed transaction management service |
|||
|
|||
### 英文[] |
|||
### 中文 |
|||
|
|||
近期频繁更新中 |
|||
@ -1,6 +1,29 @@ |
|||
# a lightweight distributed transaction management service |
|||
## 轻量级分布式事务管理服务 |
|||
* 跨语言 |
|||
- 语言无关,基于http协议 |
|||
* 多种协议支持 |
|||
- 支持xa、tcc、saga |
|||
## 运行示例 |
|||
### dtm依赖于mysql |
|||
使用已有的mysql: |
|||
`cp conf.sample.yml conf.yml # 修改conf.yml` |
|||
或者通过docker安装mysql |
|||
`docker-compose up -f compose.mysql.yml` |
|||
### 启动并运行saga示例 |
|||
`go run app/main.go` |
|||
|
|||
### 英文[] |
|||
### 中文 |
|||
## 开始使用 |
|||
|
|||
近期频繁更新中 |
|||
### 安装 |
|||
`go get github.com/yedf/dtm` |
|||
### 使用 |
|||
``` go |
|||
gid := common.GenGid() |
|||
req := &gin.H{"amount": 30} |
|||
saga := dtm.SagaNew(DtmServer, gid). |
|||
Add(startBusi+"/TransOut", startBusi+"/TransOutCompensate", req). |
|||
Add(startBusi+"/TransIn", startBusi+"/TransInCompensate", req) |
|||
err := saga.Commit() |
|||
``` |
|||
### 完整示例 |
|||
参考examples/quick_start.go |
|||
|
|||
Loading…
Reference in new issue