npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dtmcli

v0.0.12

Published

client sdk for distributed transaction framework dtm

Downloads

17

Readme

a client for distributed transaction manager dtm

dtmcli 是分布式事务管理器dtm的客户端sdk

dtm分布式事务管理服务

DTM是一款跨语言的开源分布式事务管理器,优雅的解决了幂等、空补偿、悬挂等分布式事务难题。提供了简单易用、高性能、易水平扩展的分布式事务解决方案。

亮点

  • 极易接入
    • 支持HTTP,提供非常简单的接口,极大降低上手分布式事务的难度,新手也能快速接入
  • 使用简单
    • 开发者不再担心悬挂、空补偿、幂等各类问题,框架层代为处理
  • 跨语言
    • 可适合多语言栈的公司使用。方便go、python、php、nodejs、ruby各类语言使用。
  • 易部署、易扩展
    • 仅依赖mysql,部署简单,易集群化,易水平扩展
  • 多种分布式事务协议支持
    • TCC、SAGA、XA、事务消息

与其他框架对比

目前开源的分布式事务框架,暂未看到非Java语言有成熟的框架。而Java语言的较多,有阿里的SEATA、华为的ServiceComb-Pack,京东的shardingsphere,以及himly,tcc-transaction,ByteTCC等等,其中以seata应用最为广泛。

下面是dtm和seata的主要特性对比:

| 特性| DTM | SEATA |备注| |:-----:|:----:|:----:|:----:| | 支持语言 |Golang、python、php及其他|Java|dtm可轻松接入一门新语言| |异常处理| 子事务屏障自动处理|手动处理 |dtm解决了幂等、悬挂、空补偿| | TCC事务| ||| | XA事务|||| |AT事务|||AT与XA类似,性能更好,但有脏回滚| | SAGA事务 |简单模式 |状态机复杂模式 |dtm的状态机模式在规划中| |事务消息|||dtm提供类似rocketmq的事务消息| |通信协议|HTTP|dubbo等协议,无HTTP|dtm后续将支持grpc类协议| |star数量|||dtm从20210604发布0.1,发展快|

从上面对比的特性来看,如果您的语言栈包含了Java之外的语言,那么dtm是您的首选。如果您的语言栈是Java,您也可以选择接入dtm,使用子事务屏障技术,简化您的业务编写。

typescript使用

import * as dtmcli from "dtmcli"

// 使用Msg模式需要先初始化DB model
async function startup() {
  const sequelize = await getDB();
  dtmcli.init({
    sequelize,
  });
}

async function FireTcc() {
  let dtm = "http://localhost:8080/api/dtmsvr"
  let svc = "http://localhost:4005/api/msg/testDtm"
  await dtmcli.tccGlobalTransaction(dtm, async (t: dtmcli.Tcc) => {
    let req = { amount: 30 }
    console.log("calling trans out")
    await t.callBranch(req, svc + "/TransOutTry", svc + "/TransOutConfirm", svc + "/TransOutCancel")
    console.log("calling trans in")
    await t.callBranch(req, svc + "/TransInTry", svc + "/TransInConfirm", svc + "/TransInCancel")
  })
}

async function FireSaga() {
  let dtm = "http://localhost:36789/api/dtmsvr" // dtm服务地址
  let svc = "http://localhost:4005/api" // 本地服务前缀
  let req = { amount: 30 } // 子事务需要的负荷
  const saga = new dtmcli.Saga(dtm, await dtmcli.mustGenGid(dtm))
  saga.add(svc+'/TransOut', svc+'/TransOutCompensate', req)
  saga.add(svc+'/TransIn', svc+'/TransInCompensate', req)

  await saga.submit()
}

async function FireSagaConcurrent() {
  let dtm = "http://localhost:36789/api/dtmsvr" // dtm服务地址
  let svc = "http://localhost:4005/api" // 本地服务前缀
  let req = { amount: 30 } // 子事务需要的负荷
  const saga = new dtmcli.Saga(dtm, await dtmcli.mustGenGid(dtm))

  saga.add(svc+'/TransOut', svc+'/TransOutCompensate', req)
  saga.add(svc+'/TransOut', svc+'/TransOutCompensate', req)
  saga.add(svc+'/TransIn', svc+'/TransInCompensate', req)
  saga.add(svc+'/TransIn', svc+'/TransInCompensate', req)
  saga.addBranchOrder(2, [0, 1]).addBranchOrder(3, [0, 1])
  saga.enableConcurrent()

  await saga.submit()
}

async function FireMsg() {
  let req = { amount: 30 } // 子事务需要的负荷
  const gid = await dtmcli.mustGenGid(dtm)
  const msg = new dtmcli.Msg(dtm, gid).add(`${svc }/TransOut`, req).add(`${svc }/TransIn`, req)
  await msg.prepare(`${svc }/query`)
  await msg.submit()
}


async function FireMsgWithLocalTransaction() {
  const req = { amount: 30 }
  const gid = await dtmcli.mustGenGid(dtm)
  const seuqelize = await getDB()
  const msg = new dtmcli.Msg(dtm, gid).add(`${svc }/TransIn`, req)
  await msg.doAndSubmitDB(`${svc }/query`, seuqelize, async (tx) => {
    await transUserBalance(tx, transOutUid, -req.amount)
  })
}

javascript使用

const dtmcli = require("dtmcli")

async function FireTcc() {
  let dtm = "http://localhost:8080/api/dtmsvr"
  let svc = "http://localhost:4005/api"
  await dtmcli.tccGlobalTransaction(dtm, async (t) => {
    let req = { amount: 30 }
    console.log("calling trans out")
    await t.callBranch(req, svc + "/TransOutTry", svc + "/TransOutConfirm", svc + "/TransOutCancel")
    console.log("calling trans in")
    await t.callBranch(req, svc + "/TransInTry", svc + "/TransInConfirm", svc + "/TransInCancel")
  })
}

可运行的使用示例

https://github.com/dtm-labs/dtmcli-node-sample