LCN搭建TM服务
2019-10-15 本文已影响0人
长孙俊明
所需软件
JDK1.8+
Redis3.X
Maven3.X
Mysql5.7+
安装TM服务
初始化数据
创建MySQL数据库, 名称为: tx-manager
创建数据表
CREATE TABLE `t_tx_exception` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`unit_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`mod_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`transaction_state` tinyint(4) NULL DEFAULT NULL,
`registrar` tinyint(4) NULL DEFAULT NULL,
`remark` varchar(4096) NULL DEFAULT NULL,
`ex_state` tinyint(4) NULL DEFAULT NULL COMMENT '0 未解决 1已解决',
`create_time` datetime(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
修改配置信息
spring.application.name=tx-manager
server.port=7970
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tx-manager?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.use-generated-keys=true
#tx-lcn.logger.enabled=true
# TxManager Host Ip
#tx-lcn.manager.host=127.0.0.1
# TxClient连接请求端口
#tx-lcn.manager.port=8070
# 心跳检测时间(ms)
#tx-lcn.manager.heart-time=15000
# 分布式事务执行总时间
#tx-lcn.manager.dtx-time=30000
#参数延迟删除时间单位ms
#tx-lcn.message.netty.attr-delay-time=10000
#tx-lcn.manager.concurrent-level=128
# 开启日志
#tx-lcn.logger.enabled=true
#logging.level.com.codingapi=debug
#redis 主机
#spring.redis.host=127.0.0.1
#redis 端口
#spring.redis.port=6379
#redis 密码
#spring.redis.password=
编译TM
git clone https://github.com/codingapi/tx-lcn.git & cd txlcn-tm
cd txlcn-tm
mvn clean package '-Dmaven.test.skip=true'
登录后台
访问 http://127.0.0.1:7970/admin/index.html进入管理后台,默认密码时codingapi
。
后台使用说明
首页信息
主要是TxManager的配置信息,不做特别说明。[(http://www.txlcn.org/zh-cn/docs/setting/manager.html)
异常记录
事务ID
:事务组标示
事务单元ID
:参与事务单元标示
TxClient标示
:模块标示
异常情况
:【未知】【TxManager通知事务】【TxClient查询事务状态】【事务发起方通知事务组】, 这几种异常情况
异常状态
:解决和未解决。对于系统未作出补偿的异常记录,需要系统管理员 【操作】查看当场信息,做出手动补偿
时间
:发生时间
操作
:查看异常时信息
系统日志
- 日志分类-TAG:
transaction: TxClient下达命令记录 manager: TxManager执行协调记录 - 日志内容: create group: TxClient创建事务组命令到达TxManager start join group: TxClient 开始加入事务组 over join group: TxClient 成功加事务组 notify group 1: TxManager通知TxClient提交本第事务(0回滚) notify unit exception: TxManager通知事务单元失败(此处会记录异常信息) notify group over:通知事务组结束(对于个别不能通知到的单元,会记下异常记录,不影响其它通知,异常的等待补偿)
如果搭建不成功,还有另外一种方式搭建,通过maven打成jar执行运行。
这里介绍如何在开发环境友好启动TM.
新建SpringBoot模块
新增依赖
<dependency>
<groupId>com.codingapi.txlcn</groupId>
<artifactId>txlcn-tm</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
在主类上标注 @EnableTransactionManagerServer
@SpringBootApplication
@EnableTransactionManagerServer
public class TransactionManagerApplication {
public static void main(String[] args) {
SpringApplication.run(TransactionManagerApplication.class, args);
}
}