本文主要是介紹seata-samples 下面的springcloud-erureka-seata如何運行。
準備工作
1、下載seata https://github.com/seata/seata
2、下載seata-samples https://github.com/seata/seata-samples
執行sql語句
在springcloud-eureka-seata 下面有個all.sql 執行就好了。
CREATE TABLE `account_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(255) DEFAULT NULL,
`money` int(11) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `storage_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`commodity_code` varchar(255) DEFAULT NULL,
`count` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `commodity_code` (`commodity_code`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `order_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(255) DEFAULT NULL,
`commodity_code` varchar(255) DEFAULT NULL,
`count` int(11) DEFAULT '0',
`money` int(11) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
修改配置信息
1、將seata-samples工程下面的springcloud-eureka-seata中的accout、bussiness、order、storage目錄下的application.properties中的數據庫信息修改成自己的數據庫信息。
spring.datasource.url=jdbc:mysql://localhost:3306/seata_sc?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
2、將seata工程下面的server中的registry.conf文件做相應修改:
1)、將type修改爲eureka
type = "eureka"
2)、將eureka信息修改成你本地的信息
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
啓動服務
先啓動eureka、在啓動seata-server,最後順序啓動storage、order、account、bussiness。
啓動好之後,執行下面地址就可以測試了
http://localhost:8084/purchase/commit