update to v1.4.0

This commit is contained in:
zlt
2019-03-15 10:30:51 +08:00
parent 52531b9816
commit bea4650134
78 changed files with 1126 additions and 62 deletions
+16
View File
@@ -0,0 +1,16 @@
<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>central-platform</artifactId>
<version>1.4.0</version>
</parent>
<artifactId>zlt-demo</artifactId>
<packaging>pom</packaging>
<modules>
<!-- txlcn分布式事务demo -->
<module>txlcn-demo</module>
</modules>
</project>
+48
View File
@@ -0,0 +1,48 @@
[TOC]
## 一、说明
本demo是通过tx-lcn测试lcn模式的分布式事务,主要是模拟以下两个场景
1. `service-a` 调用`service-b`调用`service-c` 都成功
2. `service-a` 调用`service-b`调用`service-c` 最后`service-a`抛出异常全部回滚
&nbsp;
## 二、运行步骤
### 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`地址和数据库地址
&nbsp;
## 三、启动模块与测试
### 1. 正常提交事务
访问 发起方提供的Rest接口 `/txlcn?value=the-value`。发现事务全部提交
![result](https://www.txlcn.org/img/docs/result.png)
### 2. 回滚事务
访问 发起方提供的Rest接口 `/txlcn?value=the-value&ex=throw`。发现发起方由本地事务回滚,而参与方ServiceB、ServiceC,由于TX-LCN的协调,数据也回滚了。
![error_result](https://www.txlcn.org/img/docs/error_result.png)
+39
View File
@@ -0,0 +1,39 @@
<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>1.4.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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>
@@ -0,0 +1,69 @@
<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>1.4.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>org.springframework.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-ribbon-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.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>
@@ -0,0 +1,27 @@
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;
}
@@ -0,0 +1,22 @@
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 deleteByKId(Long id);
}
@@ -0,0 +1,17 @@
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 {
}
@@ -0,0 +1,18 @@
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", fallback = ServiceBFallback.class)
public interface ServiceBClient {
@GetMapping("/rpc")
String rpc(@RequestParam("value") String name);
}
@@ -0,0 +1,17 @@
package org.txlcn.demo.common.spring;
import org.springframework.stereotype.Component;
/**
* Description:
* Date: 19-2-19 下午1:53
*
* @author ujued
*/
@Component
public class ServiceBFallback implements ServiceBClient {
@Override
public String rpc(String name) {
return "fallback";
}
}
@@ -0,0 +1,18 @@
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", fallback = ServiceCFallback.class)
public interface ServiceCClient {
@GetMapping("/rpc")
String rpc(@RequestParam("value") String name);
}
@@ -0,0 +1,19 @@
package org.txlcn.demo.common.spring;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* Description:
* Date: 19-2-19 下午1:53
*
* @author ujued
*/
@Component
@Slf4j
public class ServiceCFallback implements ServiceCClient {
@Override
public String rpc(String name) {
return "fallback";
}
}
@@ -0,0 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.txlcn.demo.common.spring.FeignConfiguration
@@ -0,0 +1,29 @@
<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>1.4.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>
@@ -0,0 +1,21 @@
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 ServiceAApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceAApplication.class, args);
}
}
@@ -0,0 +1,29 @@
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);
}
}
@@ -0,0 +1,14 @@
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 {
}
@@ -0,0 +1,12 @@
package org.txlcn.demo.servicea;
/**
* Description:
* Date: 2018/12/25
*
* @author ujued
*/
public interface DemoService {
String execute(String value, String ex, String flag);
}
@@ -0,0 +1,55 @@
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";
}
}
@@ -0,0 +1,19 @@
spring:
datasource:
driver-class-name: com.mysql.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.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}
@@ -0,0 +1,14 @@
server:
port: 12011
zlt:
nacos:
server-addr: 192.168.28.130:8848
spring:
application:
name: txlcn-demo-spring-service-a
cloud:
nacos:
discovery:
server-addr: ${zlt.nacos.server-addr}
@@ -0,0 +1,28 @@
<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>1.4.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>
@@ -0,0 +1,21 @@
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);
}
}
@@ -0,0 +1,26 @@
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);
}
}
@@ -0,0 +1,14 @@
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 {
}
@@ -0,0 +1,12 @@
package org.txlcn.demo.serviceb;
/**
* Description:
* Date: 2018/12/25
*
* @author ujued
*/
public interface DemoService {
String rpc(String value);
}
@@ -0,0 +1,41 @@
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";
}
}
@@ -0,0 +1,19 @@
spring:
datasource:
driver-class-name: com.mysql.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.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}
@@ -0,0 +1,14 @@
server:
port: 12002
zlt:
nacos:
server-addr: 192.168.28.130:8848
spring:
application:
name: txlcn-demo-spring-service-b
cloud:
nacos:
discovery:
server-addr: ${zlt.nacos.server-addr}
@@ -0,0 +1,28 @@
<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>1.4.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>
@@ -0,0 +1,21 @@
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);
}
}
@@ -0,0 +1,24 @@
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);
}
}
@@ -0,0 +1,14 @@
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 {
}
@@ -0,0 +1,12 @@
package org.txlcn.demo.servicec;
/**
* Description:
* Date: 2018/12/25
*
* @author ujued
*/
public interface DemoService {
String rpc(String value);
}
@@ -0,0 +1,48 @@
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";
}
}
@@ -0,0 +1,19 @@
spring:
datasource:
driver-class-name: com.mysql.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.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}
@@ -0,0 +1,14 @@
server:
port: 12003
zlt:
nacos:
server-addr: 192.168.28.130:8848
spring:
application:
name: txlcn-demo-spring-service-c
cloud:
nacos:
discovery:
server-addr: ${zlt.nacos.server-addr}
+23
View File
@@ -0,0 +1,23 @@
--
-- 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;