Project

dtmcli

0.0
No commit activity in last 3 years
No release in over 3 years
dtm is a lightweight distributed transaction manager
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.8, >= 5.8.4
~> 3.13.0
~> 2.2

Runtime

~> 1.6.0
 Project Readme

dtmcli

A Ruby SDK for distributed transaction manager dtm

Usage

gem install dtmcli

Example

Business case description

dtm_url = '127.0.0.1:8080/api/dtm'
biz_url = '127.0.0.1:3000/api/biz'

# Model TCC
res = Dtmcli::Tcc.tcc_global_transaction(dtm_url) do |tcc|
  body = {amount: 30}
  print "calling trans out\n"
  tcc.call_branch(body, biz_url + '/TransOutTry', biz_url + '/TransOutConfirm', biz_url + '/TransOutCancel')
  print "calling trans in\n"
  tcc.call_branch(body, biz_url + '/TransInTry', biz_url + '/TransInConfirm', biz_url + '/TransInCancel')
end

# Model Saga
saga = Dtmcli::Saga.new(dtm_url)
saga.gen_gid

post_data = {
  amount:         30,
  transInResult:  "SUCCESS",
  transOutResult: "SUCCESS",
}
saga.add(biz_url + '/TransOut', biz_url + '/TransOutRevert', post_data)
saga.add(biz_url + '/TransIn', biz_url + '/TransInRevert', post_data)

saga.submit

# Model Transcation Msg
dtm_msg = Dtmcli::Msg.new(dtm_url)
dtm_msg.gen_gid

post_data = {amount: 30}
dtm_msg.add(biz_url + '/TransOut', post_data)
dtm_msg.add(biz_url + '/TransIn', post_data)

dtm_msg.prepare(biz_url + '/TransQuery')

dtm_msg.submit