1.3 快速开始(docker-compose)
1.3.1 关于本节
- 本节内容为您介绍如何通过txle的docker-compose文件来启动txle服务端和业务demo
1.3.2 安装准备
- 安装docker
- 安装docker-compose
1.3.3 安装过程
从txle项目中下载最新的docker-compose.yml文件
https://github.com/actiontech/txle/blob/master/docker-images/docker-compose.yml
使用docker-compose up -d
命令直接启动txle,compose配置文件会从dockerhub拉取镜像并最终启动txle服务端和业务demo
1.3.4 使用工具发起全局事务
- 发起转账1元,转账将会成功
$ curl http://${host_address}:8000/testGlobalTransaction/1/1/1 $ ok
访问数据库查看账户余额
$ docker exec -it backend-mysql bash # mysql -uroot -p123456 mysql> select * from db1.txle_sample_transfer; +----+--------+------------+---------+--------+--------+---------+---------------------+ | id | userid | merchantid | amount | payway | status | version | createtime | +----+--------+------------+---------+--------+--------+---------+---------------------+ | 1 | 1 | 1 | 1.00000 | 1 | 1 | 0 | 2019-10-30 09:47:54 | +----+--------+------------+---------+--------+--------+---------+---------------------+ 1 row in set (0.00 sec) mysql> select * from db2.txle_sample_user; +----+------+-----------+---------+---------------------+ | id | name | balance | version | createtime | +----+------+-----------+---------+---------------------+ | 1 | user | 999.00000 | 1 | 2019-10-30 09:47:30 | +----+------+-----------+---------+---------------------+ 1 row in set (0.00 sec) mysql> select * from db3.txle_sample_merchant; +----+----------+---------+---------+---------------------+ | id | name | balance | version | createtime | +----+----------+---------+---------+---------------------+ | 1 | merchant | 1.00000 | 1 | 2019-10-30 09:47:31 | +----+----------+---------+---------+---------------------+ 1 row in set (0.00 sec)
txle_sample_transfer
记录了一条交易成功的记录,txle_sample_user
和txle_sample_merchant
数据正常记录- 根据示例代码里的设定发起转账金额大于200元,第二个子服务merchant会报错导致转账将会失败
$ curl http://${host_address}:8000/testGlobalTransaction/1/300/1 $ {"timestamp":1572429018848,"status":500,"error":"Internal Server Error","exception":"org.springframework.web.client.HttpServerErrorException","message":"500 null","path":"/testGlobalTransaction/1/300/1"}
访问数据库查看账户余额
$ docker exec -it backend-mysql bash # mysql -uroot -p123456 mysql> select * from db1.txle_sample_transfer; +----+--------+------------+-----------+--------+--------+---------+---------------------+ | id | userid | merchantid | amount | payway | status | version | createtime | +----+--------+------------+-----------+--------+--------+---------+---------------------+ | 1 | 1 | 1 | 1.00000 | 1 | 1 | 0 | 2019-10-30 09:47:54 | | 2 | 1 | 1 | 300.00000 | 1 | 2 | 0 | 2019-10-30 09:50:18 | +----+--------+------------+-----------+--------+--------+---------+---------------------+ 2 rows in set (0.00 sec) mysql> select * from db2.txle_sample_user; +----+------+-----------+---------+---------------------+ | id | name | balance | version | createtime | +----+------+-----------+---------+---------------------+ | 1 | user | 999.00000 | 1 | 2019-10-30 09:47:30 | +----+------+-----------+---------+---------------------+ 1 row in set (0.00 sec) mysql> select * from db3.txle_sample_merchant; +----+----------+---------+---------+---------------------+ | id | name | balance | version | createtime | +----+----------+---------+---------+---------------------+ | 1 | merchant | 1.00000 | 1 | 2019-10-30 09:47:31 | +----+----------+---------+---------+---------------------+ 1 row in set (0.01 sec)
txle_sample_transfer
记录了一条交易失败的记录,txle_sample_user
和txle_sample_merchant
数据回滚