Springboot2.X基于可靠消息rabbitmq最终一致性分布式事务+分布式全局唯一ID生成器

代码:https://download.csdn.net/download/qq_22049773/12686929

1、代码未实现部分

     a、积分、红包相关代码未实现,按照下单逻辑操作即可

     b、quatz调度未实现,这个相当简单,可以通过dubbo等rpc方式、或者httpclient方式进行远程调度,相关代码:

           https://download.csdn.net/download/qq_22049773/12540998

     c、其他均已实现

     d、分布式全局ID生成器,ID生成非绝对递增有序,是趋向有序,这一点如果能接受,可以直接copy使用

2、事务回滚机制说明

       a、每个消费端的事务处理都由本地事务负责

       b、基于下单队列消费端临时表,查询红包、积分两个队列消费端的临时表中该订单的处理的状态,如果全部为消费成功,则更新业务订单表中的订单状态由  下单中  --》 待付款并删除所有临时表数据,如果非全部消费成功,则将定性为异常单并写入补单队列,并删除所有临时表数据。该逻辑有定时调度完成。

 

SQL:

/*
Navicat MySQL Data Transfer

Source Server         : mysql-master
Source Server Version : 50730
Source Host           : 192.168.152.16:3339
Source Database       : test

Target Server Type    : MYSQL
Target Server Version : 50730
File Encoding         : 65001

Date: 2020-08-05 22:03:06
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for ip_code
-- ----------------------------
DROP TABLE IF EXISTS `ip_code`;
CREATE TABLE `ip_code` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `ip` varchar(15) DEFAULT NULL COMMENT '服务器IP',
  `code` int(2) DEFAULT NULL COMMENT 'IP对应编号',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of ip_code
-- ----------------------------
INSERT INTO `ip_code` VALUES ('2', '192.168.192.1', '1');

-- ----------------------------
-- Table structure for local_order_consumer
-- ----------------------------
DROP TABLE IF EXISTS `local_order_consumer`;
CREATE TABLE `local_order_consumer` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `orderNumber` bigint(19) NOT NULL,
  `message` varchar(500) DEFAULT NULL,
  `status` int(1) NOT NULL COMMENT ' 0消费中,1消费成功,2消费失败',
  `consumerDate` datetime DEFAULT NULL COMMENT '本次消费时间',
  `consumerCount` int(1) DEFAULT NULL COMMENT '重复消费次数',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_orderNumber` (`orderNumber`) USING HASH
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of local_order_consumer
-- ----------------------------

-- ----------------------------
-- Table structure for local_order_product
-- ----------------------------
DROP TABLE IF EXISTS `local_order_product`;
CREATE TABLE `local_order_product` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `orderNumber` bigint(19) NOT NULL,
  `message` varchar(500) DEFAULT NULL,
  `status` int(1) NOT NULL COMMENT ' 0推送中,1推送成功,2推送失败',
  `sendDate` datetime DEFAULT NULL COMMENT '本次发送时间',
  `sendCount` int(1) DEFAULT NULL COMMENT '重发次数',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_orderNumber` (`orderNumber`) USING HASH
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of local_order_product
-- ----------------------------

-- ----------------------------
-- Table structure for orders
-- ----------------------------
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `orderNumber` bigint(19) DEFAULT NULL COMMENT '订单编号',
  `status` int(1) DEFAULT NULL COMMENT '订单状态  0待付款   1已付款  2订单取消  3已付款  4已退款',
  `goodsId` int(32) DEFAULT NULL COMMENT '商品ID',
  `userId` int(32) DEFAULT NULL COMMENT '用户ID',
  `createTime` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_orderNumber` (`orderNumber`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of orders
-- ----------------------------

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `age` int(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of users
-- ----------------------------

-- ----------------------------
-- Table structure for whole_order_id
-- ----------------------------
DROP TABLE IF EXISTS `whole_order_id`;
CREATE TABLE `whole_order_id` (
  `id` int(5) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `orderNumber` bigint(64) NOT NULL,
  `ip` varchar(15) DEFAULT NULL COMMENT '服务器IP',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_orderNumber` (`orderNumber`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of whole_order_id
-- ----------------------------
INSERT INTO `whole_order_id` VALUES ('3', '4000', '192.168.192.1');

 

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页