English | 简体中文
Minimal usage example for client/dtmgrpc
Refer to dtm installation and running
go run main.go
The order of execution can be seen in the log of dtmgrpc-qs as follows.
- TransOut
- TransIn
The entire saga transaction was executed successfully
gid := shortuuid.New()
req := &busi.BusiReq{Amount: 30} // load of the microservice
saga := dtmgrpc.NewSagaGrpc(busi.DtmGrpcServer, gid).
// Add a subtransaction of TransOut, the forward action is grpc url: busi.BusiGrpc+"/busi.Busi/TransOut", and the compensating action is similar
Add(busi.BusiGrpc+"/busi.Busi/TransOut", busi.BusiGrpc+"/busi.Busi/TransOutRevert", req).
// Add a subtransaction of TransIn, with grpc url: busi.BusiGrpc+"/busi.Busi/TransIn", and the compensating action is similar
Add(busi.BusiGrpc+"/busi.Busi/TransIn", busi.BusiGrpc+"/busi.Busi/TransInRevert", req)
// commit saga transaction, dtm will complete all subtransactions/rollback all subtransactions
err := saga.Submit()