Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Outline

English | 简体中文

dtmcli-qs

Minimal usage example for client/dtmcli

Quick start

Installing and running dtm

Refer to dtm installation and running

Startup example

go run main.go

Output

The order of execution can be seen in the log of dtmcli-qs as follows.

  • TransOut
  • TransIn

The entire saga transaction was executed successfully

Example interpretation

  // Business-specific microservice address
  const qsBusi = "http://localhost:8081/api/busi_saga"
  req := &gin.H{"amount": 30} // load of the microservice
  // DtmServer is the address of the DTM service and is a url
  DtmServer := "http://localhost:36789/api/dtmsvr"
  saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
    // Add a subtransaction of TransOut, the forward action is url: qsBusi+"/TransOut" and the compensating action is url: qsBusi+"/TransOutCom"
    Add(qsBusi+"/TransOut", qsBusi+"/TransOutCom", req).
    // Add a subtransaction of TransIn, with url: qsBusi+"/TransIn" for the forward operation and url: qsBusi+"/TransInCom" for the compensating operation
    Add(qsBusi+"/TransIn", qsBusi+"/TransInCom", req)
  // commit saga transaction, dtm will complete all subtransactions/rollback all subtransactions
  err := saga.Submit()

For more examples, see dtm-examples

Morty Proxy This is a proxified and sanitized view of the page, visit original site.