# flexible-transaction-event-demo **Repository Path**: allenzones/flexible-transaction-event-demo ## Basic Information - **Project Name**: flexible-transaction-event-demo - **Description**: spring cloud 微服务柔性事务-基于消息驱动实现最终一致性事务。 使用activemq作为消息投递 重写feign Invocation,当检测到有事务时,使用消息方式投递 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 3 - **Created**: 2018-04-01 - **Last Updated**: 2022-07-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # flexible-transaction-event-demo spring cloud 微服务柔性事务-基于消息驱动实现最终一致性事务。 使用activemq作为消息投递 重写feign Invocation,当检测到有事务时,使用消息方式投递 ## 项目介绍 **flexible-event-core**: 这是核心代码 - 重写feign invocation ,当执行方法时,注明使用事务方法Transactional时,不进行http访问,而是使用jms进行消息投递。 - 初始化jms,使其监听队列spring.application.name也就是注册到eureka的服务名称。 - 投递消息,使用原型方式,对于每个远程消息事务,重feign取出服务名,向该服务队列投递消息。 **flexible-common**: 通用代码 **flexible-ms-register**: eureka服务发现 **flexible-ms-order**: 发起者 **flexible-ms-point**:参与者 ## 启动方式: 1. 使用数据库脚本创建数据库,以及表。 2. 配置mysql,activemq 3. 启动flexible-ms-register ,这是eureka服务发现 4. 分别启动flexible-transaction-sample中的order,以及point服务 5. 发送http post 请求http://localhost:8081/v1/order/save?userId=1&point=2 完成一次基于消息驱动的柔性事务。 ## 数据库脚本 order ```mysql SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for order_record -- ---------------------------- DROP TABLE IF EXISTS `order_record`; CREATE TABLE `order_record` ( `id` varchar(100) DEFAULT NULL, `user_id` varchar(50) DEFAULT NULL, `price` int(11) DEFAULT NULL, KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Records of order_record -- ---------------------------- INSERT INTO `order_record` VALUES ('7ef0728bd11a4f00803bb08020423f35', '1', '20'); INSERT INTO `order_record` VALUES ('6ae3f9749cdb42e58ea3fd2f6839ed10', '1', '20'); ``` point ```mysql SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for user_point -- ---------------------------- DROP TABLE IF EXISTS `user_point`; CREATE TABLE `user_point` ( `id` varchar(50) NOT NULL, `user_id` varchar(50) DEFAULT NULL, `point` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Records of user_point -- ---------------------------- INSERT INTO `user_point` VALUES ('1', '1', '808'); ``` ## 说明 微服务的柔性事务大概由三种,消息最终一致性事务,最大努力通知事务,Tcc事务。本人从事编程行业不久,还是个rookie,但是非常热衷于微服务架构,兴趣原因想研究柔性事务,研究了很多大神的代码,在后面整合好到的完整版本中会一一列举出来的,先在这里感谢大神,如果由侵犯到开源规则的,本人可以修改。本人修改的柔性事务之一的tcc事务还在debug中,还有这个消息驱动事务,还没编写完全。会更新一下两点: 1. 事务信息持久化 2. 设置事务最大重试次数 3. 提高可用性