diff --git a/.gitignore b/.gitignore
index e7ad09b..d4dd614 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,4 +24,4 @@ hs_err_pid*
.idea
*.iml
-/target
\ No newline at end of file
+/*/target/
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index d9b58da..9161855 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2021 yedf
+Copyright (c) 2022 dtm-labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/NewVersion.md b/NewVersion.md
new file mode 100644
index 0000000..883524d
--- /dev/null
+++ b/NewVersion.md
@@ -0,0 +1,17 @@
+# new version
+新版本相比于旧版本Java client的的改造
+## 旧版本客户端
+
+### 旧版本在设计上可以改进的一些地方
+1.引入的类从引入路径看不出来自哪个jar包,比如exception.FailureException。在大型项目中可能会出现多个相同的类名,如果不明确包名可能会导致意义混乱,甚至引入冲突。
+2.tcc等类直接依赖了dtmsvr信息,这样的依赖方式对后期的维护不友好,如果修改了DtmServerInfo的属性,那么后期需要修改所有支持的方式。应该做一个客户端这样的东西专门用来发送请求。
+3.向dtmsvr传递参数时使用了map来传递,虽然这对用户是无感知的,但是客户在debug的时候使用map比较麻烦,感觉使用一个param对象比较好
+## 新版本客户端
+
+### 新版本中改进的地方
+1.由于新版本需要同时支持http和feign两种交互方式,因此将请求dtmsvr相关的部分以及整个client的公共部分抽取出来形成了dtmcli-common模块,这样后续如果需要支持更多的交互方式只需要改动dtmcli-common中的代码,并在core新增代码
+2.springcloud版本的client不在乎需要传入ipport这样的配置参数,一切通过feign+nacos/euraka集成起来处理。因此将java-client和spring-client分开处理了
+3.对于一些非springcloud的项目我们也提供了java-client来处理,java-client支持像以前那样直接配置endpoint的方式,同时为了适配frontend服务,也支持通过配置nacos服务中心地址这样的方式来动态查找dtmsvr具体的地址。
+4.优化了整个项目的包结构,让引入dtmcli-java的时候能够快速找到来自哪个包
+
+
diff --git a/README.md b/README.md
index 12ca8cb..277143b 100644
--- a/README.md
+++ b/README.md
@@ -45,29 +45,18 @@ DTM是一款跨语言的开源分布式事务管理器,优雅的解决了幂
## 使用方式
-### 步骤一:JitPack 存储库添加到您的构建文件
-
-Maven:
-
-```bash
-
-
- jitpack.io
- https://jitpack.io
-
-
-```
-
-Gradle:
-
-```bash
-allprojects {
- repositories {
- ...
- maven { url 'https://jitpack.io' }
- }
- }
-```
+### 步骤一:确定你需要使用的版本
+1. 您的项目是springcloud项目
+- 您的项目中springboot版本>=2.4.0,请选择dtmcli-springcloud相应的版本直接接入即可
+- 您的项目中的springboot版本<2.4.0,请选择dtmcli-java接入,dtmcli-java也提供了微服务相关的接口,请设置nacos服务中心的相关配置即可使用
+2. 您的项目是普通项目/没有接入微服务的spring(boot)项目
+- 请选择dtmcli-java,并设置相应的配置即可
+
+| artifact| version | 适用版本 |备注|
+|:-----:|:----:|:----:|:----:|
+|dtmcli-springcloud| 2.1.4.1| 2.4.0 <= springboot version < 2.5.13| springboot 版本>=2.5.0,需要设置spring.cloud.compatibility-verifier.enabled=false|
+|dtmcli-springcloud| 2.1.4.2| 2.6.0 <= springboot version < 2.6.latest| |
+|dtmcli-java| 2.1.4| others| |
### 步骤二:添加依赖项
@@ -75,9 +64,9 @@ Maven:
```bash
- com.github.yedf
- dtmcli-java
- Tag
+ io.github.dtm-labs
+ dtmcli-springcloud
+ ${dtmcli.version}
```
@@ -85,10 +74,25 @@ Gradle:
```bash
dependencies {
- implementation 'com.github.yedf:dtmcli-java:Tag'
+ implementation 'io.github.dtm-labs:dtmcli-springcloud:${dtmcli.version}'
}
```
+### 步骤三:设置dtmcli-java配置
+如果您引入了dtmcli-java,则需要新建一个`dtm-conf.properties`配置文件
+- 情形一:您引入了nacos等服务中心组件的配置文件
+```
+serverAddr=127.0.0.1:8848
+username=nacos
+password=nacos
+namespace=c3dc917d-906a-429d-90a9-85012b41014e
+dtm.service.name=dtmService
+dtm.service.registryType=nacos
+```
+- 情形二:您直连dtmsvr
+```
+dtm.ipport=127.0.0.1:36789
+```
## 示例
```bash
@@ -125,10 +129,14 @@ dependencies {
### 完整示例
-[dtmcli-java-sample](https://github.com/dtm-labs/dtmcli-java-sample)
+#### dtmcli-java使用示例
+[dtmcli-java-sample](https://github.com/dtm-labs/dtmcli-java-sample)
+[dtmcli-java-sample-use-configuration](https://github.com/horseLk/dtmcli-java-sample-with-conf)
+#### dtmcli-springcloud使用示例
+[dtmcli-java-spring-sample](https://github.com/dtm-labs/dtmcli-java-spring-sample)
### License
[MIT](https://github.com/dtm-labs/dtmcli/blob/master/LICENSE)
-[license-badge]: https://img.shields.io/github/license/dtm-labs/dtmcli-py
\ No newline at end of file
+[license-badge]: https://img.shields.io/github/license/dtm-labs/dtmcli-py
diff --git a/dtmcli-common/pom.xml b/dtmcli-common/pom.xml
new file mode 100644
index 0000000..8f58649
--- /dev/null
+++ b/dtmcli-common/pom.xml
@@ -0,0 +1,60 @@
+
+
+
+ dtmcli-java-parent
+ io.github.dtm-labs
+ 2.1.4
+
+ 4.0.0
+
+ dtmcli-common
+ 2.1.4
+ jar
+ dtmcli-common
+
+
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ io.github.openfeign
+ feign-core
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+ com.squareup.okhttp3
+ okhttp
+
+
+
+ com.alibaba.nacos
+ nacos-client
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+
\ No newline at end of file
diff --git a/dtmcli-common/src/main/java/pub/dtm/client/constant/Constants.java b/dtmcli-common/src/main/java/pub/dtm/client/constant/Constants.java
new file mode 100644
index 0000000..a0fb213
--- /dev/null
+++ b/dtmcli-common/src/main/java/pub/dtm/client/constant/Constants.java
@@ -0,0 +1,66 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 dtm-labs
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package pub.dtm.client.constant;
+
+/**
+ * Constants
+ *
+ * @author horseLk
+ */
+public class Constants {
+ public static final String MICRO_SERVICE_NAME_KEY = "dtm.service.name";
+
+ public static final String GET_METHOD = "GET ";
+
+ public static final String POST_METHOD = "POST ";
+
+ public static final String HTTP_PREFIX = "http://";
+
+ public static final String HTTPS_PREFIX = "https://";
+
+ public static final String PING_URL = "/api/ping";
+
+ private static final String BASE_URL = "/api/dtmsvr";
+
+ public static final String NEW_GID_URL = BASE_URL + "/newGid";
+
+ public static final String PREPARE_URL = BASE_URL + "/prepare";
+
+ public static final String SUBMIT_URL = BASE_URL + "/submit";
+
+ public static final String ABORT_URL = BASE_URL + "/abort";
+
+ public static final String REGISTER_BRANCH_URL = BASE_URL + "/registerBranch";
+
+ public static final String DEFAULT_STATUS = "prepared";
+
+ public static final String EMPTY_STRING = "";
+
+ public static final String SUCCESS_RESULT = "SUCCESS";
+
+ public static final String FAILURE_RESULT = "FAILURE";
+
+ public static final int RESP_ERR_CODE = 400;
+}
diff --git a/src/main/java/common/constant/ParamFieldConstant.java b/dtmcli-common/src/main/java/pub/dtm/client/constant/ParamFieldConstants.java
similarity index 93%
rename from src/main/java/common/constant/ParamFieldConstant.java
rename to dtmcli-common/src/main/java/pub/dtm/client/constant/ParamFieldConstants.java
index 3da26d0..0a38075 100644
--- a/src/main/java/common/constant/ParamFieldConstant.java
+++ b/dtmcli-common/src/main/java/pub/dtm/client/constant/ParamFieldConstants.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2021 yedf
+ * Copyright (c) 2022 dtm-labs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,13 +22,14 @@
* SOFTWARE.
*/
-package common.constant;
+package pub.dtm.client.constant;
/**
- * @author lixiaoshuang
+ * Constants for dtm server parameter key
+ *
+ * @author horseLk
*/
-public class ParamFieldConstant {
-
+public class ParamFieldConstants {
public static final String GID = "gid";
public static final String TRANS_TYPE = "trans_type";
@@ -72,5 +73,4 @@ public class ParamFieldConstant {
public static final String PASSTHROGH_HEADERS = "passthrough_headers";
public static final String BRANCH_HEADERS = "branch_headers";
-
}
diff --git a/src/main/java/common/model/TransBase.java b/dtmcli-common/src/main/java/pub/dtm/client/enums/TransTypeEnum.java
similarity index 56%
rename from src/main/java/common/model/TransBase.java
rename to dtmcli-common/src/main/java/pub/dtm/client/enums/TransTypeEnum.java
index 9d3ecdf..21d881b 100644
--- a/src/main/java/common/model/TransBase.java
+++ b/dtmcli-common/src/main/java/pub/dtm/client/enums/TransTypeEnum.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2021 yedf
+ * Copyright (c) 2022 dtm-labs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,49 +22,57 @@
* SOFTWARE.
*/
-package common.model;
+package pub.dtm.client.enums;
-import common.enums.TransTypeEnum;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-@Data
-@NoArgsConstructor
-public class TransBase {
-
+/**
+ * Transtype enum
+ *
+ * @author horseLk
+ */
+public enum TransTypeEnum {
/**
- * 全局事务id
+ * tcc
*/
- private String gid;
-
+ TCC("tcc"),
/**
- * 事务类型
+ * xa
*/
- private TransTypeEnum transTypeEnum;
-
- private boolean waitResult;
-
- private long timeoutToFail;
-
- private long retryInterval;
+ XA("xa"),
+ /**
+ * msg
+ */
+ MSG("msg"),
+ /**
+ * saga
+ */
+ SAGA("saga")
+ ;
- private Map branchHeaders = new HashMap<>();
+ TransTypeEnum(String value) {
+ this.value = value;
+ }
- private ArrayList passthroughHeaders = new ArrayList<>();
+ /**
+ * Trans type string
+ */
+ private final String value;
- private String customData;
+ public String getValue() {
+ return this.value;
+ }
- private ArrayList