dtm/examples/saga_wait.go
2021-08-11 19:12:05 +08:00

24 lines
738 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package examples
import (
"github.com/yedf/dtm/dtmcli"
)
// SagaWaitFireRequest 1
func SagaWaitFireRequest() string {
dtmcli.Logf("a saga busi transaction begin")
req := &TransReq{
Amount: 30,
TransInResult: "SUCCESS",
TransOutResult: "SUCCESS",
}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
saga.WaitResult = true // 设置为等待结果模式后面的submit调用会等待服务器处理这个事务。如果Submit正常返回那么整个全局事务已成功完成
err := saga.Submit()
dtmcli.Logf("result gid is: %s", saga.Gid)
dtmcli.FatalIfError(err)
return saga.Gid
}