Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Official java client for distributed transaction framework dtm

License

NotificationsYou must be signed in to change notification settings

dtm-labs/dtmcli-java

Repository files navigation

English |简体中文

dtmcli-java is the Java client SDK for distributed transaction managerdtm

What is DTM

DTM is a distributed transaction framework which provides cross-service eventual data consistency. It provides saga, tcc, xa, 2-phase message, outbox patterns for a variety of application scenarios. It also supports multiple languages and multiple store engine to form up a transaction as following:

function-picture

Features

  • Support for multiple languages: Go, Java, PHP, C#, Python, Nodejs SDKs
  • Support for multiple transaction patterns: SAGA, TCC, XA
  • Support for OutBox pattern: 2-phase messages, a more elegant solution than OutBox
  • Support for multiple database transactions: Mysql, Redis, MongoDB, Postgres, TDSQL, etc.
  • Support for multiple storage engines: Mysql (common), Redis (high performance), MongoDB (in planning)
  • Support for multiple microservices architectures:go-zero, go-kratos/kratos, polarismesh/polaris
  • Support for high availability and easy horizontal scaling

Usage

Step 1: Determine the version

  1. Springcloud Projects
  • If the version of springboot >= 2.4.0, choose a corresponding version of dtmcli-springcloud.
  • If the version of springboot <> 2.4.0, use dtmcli-java, it provide the interfaces for micro-services, please set the configuration for nacos.
  1. Not Springcloud Projects.
  • use dtmcli-java,and set your configurations.
artifactversiondtmcli-java versionremark
dtmcli-springcloud2.1.4.12.4.0 <= springboot version < 2.5.13for springboot >= 2.5.0,please set spring.cloud.compatibility-verifier.enabled=false
dtmcli-springcloud2.1.4.22.6.0 <= springboot version < 2.6.latest
dtmcli-java2.1.4others

Step 2: Add Dependencies

Maven:

<dependency><groupId>io.github.dtm-labs</groupId><artifactId>dtmcli-springcloud</artifactId><version>${dtmcli.version}</version></dependency>

Gradle:

dependencies {        implementation'io.github.dtm-labs:dtmcli-springcloud:${dtmcli.version}'}

Step 3:Configure dtmcli-java

If you are using dtmcli-java,new a file nameddtm-conf.properties

  • Case 1: Using naceos
serverAddr=127.0.0.1:8848username=nacospassword=nacosnamespace=c3dc917d-906a-429d-90a9-85012b41014edtm.service.name=dtmServicedtm.service.registryType=nacos
  • Case 2: Connect to dtmsvr directly
dtm.ipport=127.0.0.1:36789

Sample

@RequestMapping("testTcc")    public StringtestTcc() {        // new dtm clinet        DtmClient dtmClient = new DtmClient(ipPort);        //create TCC transaction        try {dtmClient.tccGlobalTransaction(dtmClient.genGid(), TccTestController::tccTrans);        } catch (Exception e) {            log.error("tccGlobalTransaction error", e);return"fail";        }return"success";    }/*** define TCC sub-transactions by calling callBranch** @param tcc* @return* @see TransController*/    public static void tccTrans(Tcc tcc) throws Exception {        Response outResponse = tcc                .callBranch("", svc +"/TransOutTry", svc +"/TransOutConfirm", svc +"/TransOutCancel");        log.info("outResponse:{}", outResponse);        Response inResponse = tcc.callBranch("", svc +"/TransInTry", svc +"/TransInConfirm", svc +"/TransInCancel");        log.info("inResponse:{}", inResponse);    }

Complete Sample

Sample for dtmcli-java

dtmcli-java-sampledtmcli-java-sample-use-configuration

Sample for dtmcli-springcloud

dtmcli-java-spring-sample

About

Official java client for distributed transaction framework dtm

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp