feat: 删除txlcn-demo工程(由于txlcn不推荐使用了)
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<!-- txlcn分布式事务demo -->
|
||||
<module>txlcn-demo</module>
|
||||
<!-- sharding-jdbc分库分表demo -->
|
||||
<module>sharding-jdbc-demo</module>
|
||||
<!-- rocketmq消息队列demo -->
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
[TOC]
|
||||
|
||||
## 一、说明
|
||||
|
||||
本demo是通过tx-lcn测试lcn模式的分布式事务,主要是模拟以下两个场景
|
||||
|
||||
1. `service-a` 调用`service-b`调用`service-c` 都成功
|
||||
2. `service-a` 调用`service-b`调用`service-c` 最后`service-a`抛出异常全部回滚
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 二、运行步骤
|
||||
|
||||
### 1. 初始化TxManager的数据
|
||||
|
||||
执行`zlt-doc\sql\tx-manager.sql`和`zlt-doc\sql\tx_logger.sql`脚本
|
||||
|
||||
### 2. 修改TxManager的配置
|
||||
|
||||
工程目录:`zlt-transaction\txlcn-tm`,修改nacos、数据库和redis
|
||||
|
||||
### 2. 启动TxManager
|
||||
|
||||
工程目录:`zlt-transaction\txlcn-tm`
|
||||
|
||||
### 3. 初始化demo的数据
|
||||
|
||||
执行`zlt-demo\txlcn-demo\txlcn-demo.sql`脚本
|
||||
|
||||
### 4. 修改3个服务的配置
|
||||
|
||||
`nacos`地址和数据库地址
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 三、启动模块与测试
|
||||
|
||||
### 1. 正常提交事务
|
||||
访问 发起方提供的Rest接口 `/txlcn?value=the-value`。发现事务全部提交
|
||||

|
||||
|
||||
### 2. 回滚事务
|
||||
访问 发起方提供的Rest接口 `/txlcn?value=the-value&ex=throw`。发现发起方由本地事务回滚,而参与方ServiceB、ServiceC,由于TX-LCN的协调,数据也回滚了。
|
||||

|
||||
@@ -1,22 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>5.6.0</version>
|
||||
</parent>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<description>txlcn分布式事务demo</description>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<!-- 公共 -->
|
||||
<module>txlcn-demo-common</module>
|
||||
<!-- 服务a -->
|
||||
<module>txlcn-demo-spring-service-a</module>
|
||||
<!-- 服务b -->
|
||||
<module>txlcn-demo-spring-service-b</module>
|
||||
<!-- 服务c -->
|
||||
<module>txlcn-demo-spring-service-c</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -1,69 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.6.0</version>
|
||||
</parent>
|
||||
<artifactId>txlcn-demo-common</artifactId>
|
||||
<name>demo-common</name>
|
||||
<description>demo-common project for Spring Boot</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.codingapi.txlcn</groupId>
|
||||
<artifactId>txlcn-tc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.codingapi.txlcn</groupId>
|
||||
<artifactId>txlcn-txmsg-netty</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-db-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package org.txlcn.demo.common.db.domain;
|
||||
|
||||
import com.codingapi.txlcn.common.util.id.RandomUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class Demo {
|
||||
private Long id;
|
||||
private String kid = RandomUtils.randomKey();
|
||||
private String demoField;
|
||||
private String groupId;
|
||||
private Date createTime;
|
||||
private String appName;
|
||||
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package org.txlcn.demo.common.db.mapper;
|
||||
|
||||
import org.txlcn.demo.common.db.domain.Demo;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Mapper
|
||||
public interface BaseDemoMapper {
|
||||
|
||||
@Insert("insert into t_demo(kid, demo_field, group_id, create_time,app_name) values(#{kid}, #{demoField}, #{groupId}, #{createTime},#{appName})")
|
||||
void save(Demo demo);
|
||||
|
||||
@Delete("delete from t_demo where id=#{id}")
|
||||
void deleteById(Long id);
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package org.txlcn.demo.common.spring;
|
||||
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@ComponentScan
|
||||
@Configuration
|
||||
@EnableFeignClients
|
||||
public class FeignConfiguration {
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package org.txlcn.demo.common.spring;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@FeignClient(value = "txlcn-demo-spring-service-b")
|
||||
public interface ServiceBClient {
|
||||
|
||||
@GetMapping("/rpc")
|
||||
String rpc(@RequestParam("value") String name);
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package org.txlcn.demo.common.spring;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@FeignClient(value = "txlcn-demo-spring-service-c")
|
||||
public interface ServiceCClient {
|
||||
|
||||
@GetMapping("/rpc")
|
||||
String rpc(@RequestParam("value") String name);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.txlcn.demo.common.spring.FeignConfiguration
|
||||
@@ -1,29 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.6.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>txlcn-demo-spring-service-a</artifactId>
|
||||
<name>txlcn-demo-spring-service-a</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package org.txlcn.demo;
|
||||
|
||||
import com.central.common.lb.annotation.EnableFeignInterceptor;
|
||||
import com.codingapi.txlcn.tc.config.EnableDistributedTransaction;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableDistributedTransaction
|
||||
@EnableFeignInterceptor
|
||||
public class ServiceAApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceAApplication.class, args);
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@RestController
|
||||
public class DemoController {
|
||||
|
||||
private final DemoService demoService;
|
||||
|
||||
@Autowired
|
||||
public DemoController(DemoService demoService) {
|
||||
this.demoService = demoService;
|
||||
}
|
||||
|
||||
@RequestMapping("/txlcn")
|
||||
public String execute(@RequestParam("value") String value, @RequestParam(value = "ex", required = false) String exFlag
|
||||
, @RequestParam(value = "f", required = false) String flag) {
|
||||
return demoService.execute(value, exFlag, flag);
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.txlcn.demo.common.db.mapper.BaseDemoMapper;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Mapper
|
||||
public interface DemoMapper extends BaseDemoMapper {
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
public interface DemoService {
|
||||
|
||||
String execute(String value, String ex, String flag);
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package org.txlcn.demo.servicea;
|
||||
|
||||
import com.codingapi.txlcn.common.util.Transactions;
|
||||
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
|
||||
import com.codingapi.txlcn.tracing.TracingContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.txlcn.demo.common.db.domain.Demo;
|
||||
import org.txlcn.demo.common.spring.ServiceBClient;
|
||||
import org.txlcn.demo.common.spring.ServiceCClient;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DemoServiceImpl implements DemoService {
|
||||
@Resource
|
||||
private DemoMapper demoMapper;
|
||||
@Resource
|
||||
private ServiceBClient serviceBClient;
|
||||
@Resource
|
||||
private ServiceCClient serviceCClient;
|
||||
|
||||
@LcnTransaction
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String execute(String value, String exFlag, String flag) {
|
||||
String dResp = serviceBClient.rpc(value);
|
||||
// step2. call remote ServiceB
|
||||
String eResp = serviceCClient.rpc(value);
|
||||
// step3. execute local transaction
|
||||
Demo demo = new Demo();
|
||||
demo.setGroupId(TracingContext.tracing().groupId());
|
||||
demo.setDemoField(value);
|
||||
demo.setCreateTime(new Date());
|
||||
demo.setAppName(Transactions.getApplicationId());
|
||||
demoMapper.save(demo);
|
||||
|
||||
// 置异常标志,DTX 回滚
|
||||
if (Objects.nonNull(exFlag)) {
|
||||
throw new IllegalStateException("by exFlag");
|
||||
}
|
||||
|
||||
return dResp + " > " + eResp + " > " + "ok-service-a";
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/txlcn-demo?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
|
||||
## tx-manager 配置
|
||||
tx-lcn:
|
||||
ribbon:
|
||||
loadbalancer:
|
||||
dtx:
|
||||
enabled: true
|
||||
logger:
|
||||
enabled: true
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/tx_logger?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
zlt:
|
||||
loadbalance:
|
||||
version: test
|
||||
isolation:
|
||||
enabled: true
|
||||
chooser: com.central.common.lb.chooser.RandomRuleChooser
|
||||
@@ -1,6 +0,0 @@
|
||||
server:
|
||||
port: 12011
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: txlcn-demo-spring-service-a
|
||||
@@ -1,28 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.6.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>txlcn-demo-spring-service-b</artifactId>
|
||||
<name>txlcn-demo-spring-service-b</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package org.txlcn.demo;
|
||||
|
||||
import com.codingapi.txlcn.tc.config.EnableDistributedTransaction;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableDistributedTransaction
|
||||
public class ServiceBApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceBApplication.class, args);
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package org.txlcn.demo.serviceb;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@RestController
|
||||
public class DemoController {
|
||||
|
||||
@Autowired
|
||||
private DemoService demoService;
|
||||
|
||||
@GetMapping("/rpc")
|
||||
public String rpc(@RequestParam("value") String value, HttpServletRequest servletRequest) {
|
||||
return demoService.rpc(value);
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package org.txlcn.demo.serviceb;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.txlcn.demo.common.db.mapper.BaseDemoMapper;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Mapper
|
||||
public interface DemoMapper extends BaseDemoMapper {
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package org.txlcn.demo.serviceb;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
public interface DemoService {
|
||||
|
||||
String rpc(String value);
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package org.txlcn.demo.serviceb;
|
||||
|
||||
import com.codingapi.txlcn.common.util.Transactions;
|
||||
import com.codingapi.txlcn.tc.annotation.DTXPropagation;
|
||||
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
|
||||
import com.codingapi.txlcn.tc.annotation.TxcTransaction;
|
||||
import com.codingapi.txlcn.tracing.TracingContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.txlcn.demo.common.db.domain.Demo;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DemoServiceImpl implements DemoService {
|
||||
@Resource
|
||||
private DemoMapper demoMapper;
|
||||
|
||||
@Override
|
||||
@LcnTransaction
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String rpc(String value) {
|
||||
Demo demo = new Demo();
|
||||
demo.setGroupId(TracingContext.tracing().groupId());
|
||||
demo.setDemoField(value);
|
||||
demo.setAppName(Transactions.getApplicationId());
|
||||
demo.setCreateTime(new Date());
|
||||
demoMapper.save(demo);
|
||||
return "ok-service-b";
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/txlcn-demo?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
|
||||
## tx-manager 配置
|
||||
tx-lcn:
|
||||
ribbon:
|
||||
loadbalancer:
|
||||
dtx:
|
||||
enabled: true
|
||||
logger:
|
||||
enabled: true
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/tx_logger?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
zlt:
|
||||
loadbalance:
|
||||
version: test
|
||||
isolation:
|
||||
enabled: true
|
||||
@@ -1,6 +0,0 @@
|
||||
server:
|
||||
port: 12002
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: txlcn-demo-spring-service-b
|
||||
@@ -1,28 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo</artifactId>
|
||||
<version>5.6.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>txlcn-demo-spring-service-c</artifactId>
|
||||
<name>txlcn-demo-spring-service-c</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>txlcn-demo-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package org.txlcn.demo;
|
||||
|
||||
import com.codingapi.txlcn.tc.config.EnableDistributedTransaction;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableDistributedTransaction
|
||||
public class ServiceCApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceCApplication.class, args);
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package org.txlcn.demo.servicec;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@RestController
|
||||
public class DemoController {
|
||||
|
||||
@Autowired
|
||||
private DemoService demoService;
|
||||
|
||||
@GetMapping("/rpc")
|
||||
public String rpc(@RequestParam("value") String value) {
|
||||
return demoService.rpc(value);
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package org.txlcn.demo.servicec;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.txlcn.demo.common.db.mapper.BaseDemoMapper;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Mapper
|
||||
public interface DemoMapper extends BaseDemoMapper {
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package org.txlcn.demo.servicec;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
public interface DemoService {
|
||||
|
||||
String rpc(String value);
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package org.txlcn.demo.servicec;
|
||||
|
||||
import com.codingapi.txlcn.common.util.Transactions;
|
||||
import com.codingapi.txlcn.tc.annotation.DTXPropagation;
|
||||
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
|
||||
import com.codingapi.txlcn.tc.annotation.TccTransaction;
|
||||
import com.codingapi.txlcn.tc.support.DTXUserControls;
|
||||
import com.codingapi.txlcn.tracing.TracingContext;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.txlcn.demo.common.db.domain.Demo;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2018/12/25
|
||||
*
|
||||
* @author ujued
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DemoServiceImpl implements DemoService {
|
||||
@Resource
|
||||
private DemoMapper demoMapper;
|
||||
|
||||
@Override
|
||||
@LcnTransaction
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String rpc(String value) {
|
||||
Demo demo = new Demo();
|
||||
demo.setDemoField(value);
|
||||
demo.setCreateTime(new Date());
|
||||
demo.setAppName(Transactions.getApplicationId());
|
||||
demo.setGroupId(TracingContext.tracing().groupId());
|
||||
demoMapper.save(demo);
|
||||
if ("456".equals(value)) {
|
||||
throw new IllegalStateException("by test");
|
||||
}
|
||||
return "ok-service-c";
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://${zlt.datasource.ip}:3306/txlcn-demo?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
|
||||
## tx-manager 配置
|
||||
tx-lcn:
|
||||
ribbon:
|
||||
loadbalancer:
|
||||
dtx:
|
||||
enabled: true
|
||||
logger:
|
||||
enabled: true
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/tx_logger?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: ${zlt.datasource.username}
|
||||
password: ${zlt.datasource.password}
|
||||
@@ -1,6 +0,0 @@
|
||||
server:
|
||||
port: 12003
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: txlcn-demo-spring-service-c
|
||||
@@ -1,23 +0,0 @@
|
||||
--
|
||||
-- Current Database: `txlcn-demo`
|
||||
--
|
||||
|
||||
CREATE DATABASE `txlcn-demo` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
USE `txlcn-demo`;
|
||||
|
||||
--
|
||||
-- Table structure for table `t_demo`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `t_demo`;
|
||||
CREATE TABLE `t_demo` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`kid` varchar(45) DEFAULT NULL,
|
||||
`demo_field` varchar(255) DEFAULT NULL,
|
||||
`group_id` varchar(64) DEFAULT NULL,
|
||||
`unit_id` varchar(32) DEFAULT NULL,
|
||||
`app_name` varchar(128) DEFAULT NULL,
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
|
||||
Reference in New Issue
Block a user