{"id":19073378,"url":"https://github.com/dtm-labs/dtmcli-java","last_synced_at":"2025-08-21T20:31:48.686Z","repository":{"id":39872997,"uuid":"398727982","full_name":"dtm-labs/dtmcli-java","owner":"dtm-labs","description":"Official java client for distributed transaction framework dtm","archived":false,"fork":false,"pushed_at":"2024-07-10T12:05:48.000Z","size":222,"stargazers_count":26,"open_issues_count":4,"forks_count":19,"subscribers_count":12,"default_branch":"main","last_synced_at":"2024-12-13T03:41:31.271Z","etag":null,"topics":["database","distributed","distributed-transaction","dtm","saga","tcc","transaction","transactions"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dtm-labs.png","metadata":{"files":{"readme":"README-cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-22T06:11:06.000Z","updated_at":"2024-10-08T01:02:40.000Z","dependencies_parsed_at":"2022-08-09T15:35:39.444Z","dependency_job_id":null,"html_url":"https://github.com/dtm-labs/dtmcli-java","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtm-labs%2Fdtmcli-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtm-labs%2Fdtmcli-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtm-labs%2Fdtmcli-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtm-labs%2Fdtmcli-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtm-labs","download_url":"https://codeload.github.com/dtm-labs/dtmcli-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230532442,"owners_count":18240792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","distributed","distributed-transaction","dtm","saga","tcc","transaction","transactions"],"created_at":"2024-11-09T01:46:40.147Z","updated_at":"2024-12-20T04:06:48.745Z","avatar_url":"https://github.com/dtm-labs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dtmcli-java [![MIT][license-badge]](https://github.com/dtm-labs/dtmcli/blob/main/LICENSE)\n\n简体中文 | [English](./README.md)\n\n`dtmcli-java` 是分布式事务管理器 [dtm](https://github.com/dtm-labs/dtm) 的Java客户端sdk\n\n## DTM是什么\n\nDTM是一款变革性的分布式事务框架，提供了傻瓜式的使用方式，极大的降低了分布式事务的使用门槛，改变了“能不用分布式事务就不用”的行业现状，优雅的解决了服务间的数据一致性问题。\n\n## 特性\n* 支持多种语言：支持Go、Java、PHP、C#、Python、Nodejs 各种语言的SDK\n* 支持多种事务模式：SAGA、TCC、XA\n* 支持消息最终一致性：二阶段消息，比本地消息表更优雅的方案\n* 支持多种数据库事务：Mysql、Redis、MongoDB、Postgres、TDSQL等\n* 支持多种存储引擎：Mysql（常用）、Redis（高性能）、MongoDB（规划中）\n* 支持多种微服务架构：[go-zero](https://github.com/zeromicro/go-zero)、go-kratos/kratos、polarismesh/polaris\n* 支持高可用，易水平扩展\n\n## 使用方式\n\n### 步骤一：确定你需要使用的版本\n1. 您的项目是springcloud项目\n- 您的项目中springboot版本\u003e=2.4.0，请选择dtmcli-springcloud相应的版本直接接入即可\n- 您的项目中的springboot版本\u003c2.4.0，请选择dtmcli-java接入，dtmcli-java也提供了微服务相关的接口，请设置nacos服务中心的相关配置即可使用\n2. 您的项目是普通项目/没有接入微服务的spring(boot)项目\n- 请选择dtmcli-java，并设置相应的配置即可\n\n|  artifact| version | 适用版本 |备注|\n|:-----:|:----:|:----:|:----:|\n|dtmcli-springcloud| 2.1.4.1| 2.4.0 \u003c= springboot version \u003c 2.5.13| springboot 版本\u003e=2.5.0，需要设置spring.cloud.compatibility-verifier.enabled=false|\n|dtmcli-springcloud| 2.1.4.2| 2.6.0 \u003c= springboot version \u003c 2.6.latest| |\n|dtmcli-java| 2.1.4| others| |\n\n### 步骤二：添加依赖项\n\nMaven：\n\n```bash\n\u003cdependency\u003e\n\t\u003cgroupId\u003eio.github.dtm-labs\u003c/groupId\u003e\n\t\u003cartifactId\u003edtmcli-springcloud\u003c/artifactId\u003e\n\t\u003cversion\u003e${dtmcli.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nGradle:\n\n```bash\ndependencies {\n\t        implementation 'io.github.dtm-labs:dtmcli-springcloud:${dtmcli.version}'\n\t}\n```\n\n### 步骤三：设置dtmcli-java配置\n如果您引入了dtmcli-java，则需要新建一个`dtm-conf.properties`配置文件\n- 情形一：您引入了nacos等服务中心组件的配置文件\n```\nserverAddr=127.0.0.1:8848\nusername=nacos\npassword=nacos\nnamespace=c3dc917d-906a-429d-90a9-85012b41014e\ndtm.service.name=dtmService\ndtm.service.registryType=nacos\n```\n- 情形二：您直连dtmsvr\n```\ndtm.ipport=127.0.0.1:36789\n```\n## 示例\n\n```bash\n@RequestMapping(\"testTcc\")\n    public String testTcc() {\n        //创建dtm clinet\n        DtmClient dtmClient = new DtmClient(ipPort);\n        //创建tcc事务\n        try {\n            dtmClient.tccGlobalTransaction(dtmClient.genGid(), TccTestController::tccTrans);\n        } catch (Exception e) {\n            log.error(\"tccGlobalTransaction error\", e);\n            return \"fail\";\n        }\n        return \"success\";\n    }\n\n/**\n     * 定义tcc事务函数，内部需要通过callBranch注册事务子分支\n     *\n     * @param tcc\n     * @return\n     * @see TransController\n     */\n    public static void tccTrans(Tcc tcc) throws Exception {\n        Response outResponse = tcc\n                .callBranch(\"\", svc + \"/TransOutTry\", svc + \"/TransOutConfirm\", svc + \"/TransOutCancel\");\n        log.info(\"outResponse:{}\", outResponse);\n        Response inResponse = tcc.callBranch(\"\", svc + \"/TransInTry\", svc + \"/TransInConfirm\", svc + \"/TransInCancel\");\n        log.info(\"inResponse:{}\", inResponse);\n    }\n```\n\n\n### 完整示例\n\n#### dtmcli-java使用示例\n[dtmcli-java-sample](https://github.com/dtm-labs/dtmcli-java-sample)\n[dtmcli-java-sample-use-configuration](https://github.com/horseLk/dtmcli-java-sample-with-conf)\n#### dtmcli-springcloud使用示例\n[dtmcli-java-spring-sample](https://github.com/dtm-labs/dtmcli-java-spring-sample)\n\n[license-badge]: https://img.shields.io/github/license/dtm-labs/dtmcli-java\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtm-labs%2Fdtmcli-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtm-labs%2Fdtmcli-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtm-labs%2Fdtmcli-java/lists"}