1. Storage design
Shopping rebate www.cpa5.com cnIn the previous chapter, we have completed the sorting of basic business processes and the division of service modules. Next, we begin to design data storage.
Although there is no mandatory specification for the database in the micro service theory, generally, after the service is split, the database will be split accordingly.
This method of splitting based on business is vertical splitting in database splitting.
If you are lazy in database design, you will no longer use the heavy Power Designer and directly use Navicat.
According to the splitting of services, the databases are established as follows:
- shop_user:
Create table statement:
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for shop_user -- ---------------------------- DROP TABLE IF EXISTS `shop_user`; CREATE TABLE `shop_user` ( `user_id` int(16) NOT NULL AUTO_INCREMENT, `user_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'user name', `sex` tinyint(4) NULL DEFAULT 2 COMMENT 'User gender: 0: female 1: male 2: unknown', `phone` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'cell-phone number', `email` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'mailbox', `address` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'address', `count` int(64) NULL DEFAULT NULL COMMENT 'integral', `level` int(32) NULL DEFAULT 0 COMMENT 'Grade', `create_user` int(16) NULL DEFAULT NULL COMMENT 'Create user', `create_time` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT 'Creation time', `update_user` int(16) NULL DEFAULT NULL COMMENT 'Update user', `update_time` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT 'Update time', `status` tinyint(4) NULL DEFAULT 1 COMMENT 'state', PRIMARY KEY (`user_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'User table' ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;
- shop_goods:
Create table statement:
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for shop_goods -- ---------------------------- DROP TABLE IF EXISTS `shop_goods`; CREATE TABLE `shop_goods` ( `goods_id` int(16) NOT NULL AUTO_INCREMENT COMMENT 'Primary key', `goods_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'Trade name', `price` decimal(10, 2) NULL DEFAULT NULL COMMENT 'Price', `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'Product introduction', `create_user` int(16) NULL DEFAULT NULL COMMENT 'Create user', `create_time` datetime(0) NULL DEFAULT NULL COMMENT 'Creation time', `update_user` int(16) NULL DEFAULT NULL COMMENT 'Update user', `update_time` datetime(0) NULL DEFAULT NULL COMMENT 'Update time', `status` tinyint(4) NULL DEFAULT 0 COMMENT 'state', PRIMARY KEY (`goods_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;
- shop_order:
Create table statement:
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for shop_order -- ---------------------------- DROP TABLE IF EXISTS `shop_order`; CREATE TABLE `shop_order` ( `order_id` int(16) NOT NULL AUTO_INCREMENT COMMENT 'Primary key', `order_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'Order amount', `user_id` int(16) NULL DEFAULT NULL COMMENT 'user id', `order_status` tinyint(4) NULL DEFAULT NULL COMMENT 'Order status: 1: to be paid 2: paid 3: shipped 4: completed 5: closed', `comment` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'evaluate', `create_user` int(16) NULL DEFAULT NULL COMMENT 'Create user', `create_time` datetime(0) NULL DEFAULT NULL COMMENT 'Creation time', `update_user` int(16) NULL DEFAULT NULL COMMENT 'Update user', `update_time` datetime(0) NULL DEFAULT NULL COMMENT 'Update time', `status` tinyint(4) NULL DEFAULT NULL COMMENT 'state', PRIMARY KEY (`order_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for shop_order_detail -- ---------------------------- DROP TABLE IF EXISTS `shop_order_detail`; CREATE TABLE `shop_order_detail` ( `order_detail_id` int(16) NOT NULL AUTO_INCREMENT COMMENT 'Primary key', `order_id` int(16) NULL DEFAULT NULL COMMENT 'Order table PK', `goods_id` int(16) NULL DEFAULT NULL COMMENT 'Commodity table primary key', `goods_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'Trade name', `price` decimal(10, 2) NULL DEFAULT NULL COMMENT 'commodity price', `goods_count` int(32) NULL DEFAULT NULL COMMENT 'Quantity of goods', `create_user` int(16) NULL DEFAULT NULL COMMENT 'Create user', `create_time` datetime(0) NULL DEFAULT NULL COMMENT 'Creation time', `update_user` int(16) NULL DEFAULT NULL COMMENT 'Update user', `update_time` datetime(0) NULL DEFAULT NULL COMMENT 'Update time', `status` tinyint(4) NULL DEFAULT 0 COMMENT 'state', PRIMARY KEY (`order_detail_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;
shop_stock:
Create table statement:
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for shop_stock -- ---------------------------- DROP TABLE IF EXISTS `shop_stock`; CREATE TABLE `shop_stock` ( `stock_id` int(16) NOT NULL AUTO_INCREMENT COMMENT 'Primary key', `goods_id` int(16) NULL DEFAULT NULL COMMENT 'Commodity table primary key', `inventory` int(64) NULL DEFAULT NULL COMMENT 'Inventory', `create_user` int(16) NULL DEFAULT NULL COMMENT 'Create user', `create_time` datetime(0) NULL DEFAULT NULL COMMENT 'Creation time', `update_user` int(11) NULL DEFAULT NULL COMMENT 'Update user', `update_time` datetime(0) NULL DEFAULT NULL COMMENT 'Update time', `status` tinyint(4) NULL DEFAULT 0, PRIMARY KEY (`stock_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;
shop_finance:
Create table statement:
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for shop_payment_record -- ---------------------------- DROP TABLE IF EXISTS `shop_payment_record`; CREATE TABLE `shop_payment_record` ( `payment_record_id` int(16) NOT NULL AUTO_INCREMENT COMMENT 'Primary key', `order_id` int(16) NULL DEFAULT NULL COMMENT 'Order table PK', `user_id` int(16) NULL DEFAULT NULL COMMENT 'Payer', `fee` decimal(16, 2) NULL DEFAULT NULL COMMENT 'Payment amount', `pay_type` tinyint(4) NULL DEFAULT NULL COMMENT 'Payment method 1: Alipay 2: WeChat payment', `create_user` int(16) NULL DEFAULT NULL COMMENT 'Create user', `create_time` datetime(0) NULL DEFAULT NULL COMMENT 'Creation time', `update_user` int(11) NULL DEFAULT NULL COMMENT 'Update user', `update_time` datetime(0) NULL DEFAULT NULL COMMENT 'Update time', `status` tinyint(4) NULL DEFAULT 0 COMMENT 'state', PRIMARY KEY (`payment_record_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;
2. Infrastructure design
Let's first take a look at some of the official components of spring cloud. Some components are no longer maintained and upgraded, and some new components assume corresponding responsibilities again. zuul later introduced the gateway component, and eureka later introduced zookeeper compatibility.
Let's take a look at the main components of spring cloud Alibaba.
Dubbo is a high-performance Java RPC framework widely used in China.
nacos is a dynamic service discovery, configuration management and service management platform that is easy to build cloud native applications.
After the development of hystrix was stopped, it was replaced by the official Resilience4j to complete the mission, while sentinel realized the functions similar to hystrix in a simpler and lighter way, which is more in line with the dubbo ecology.
Distributed transaction has always been a very troublesome problem. seata is an easy-to-use high-performance microservice distributed transaction solution.
A rough architecture diagram of the example we want to do is as follows. Next, we will carry out our project practice around the system of SpringCloud/SpringCloud Alibaba.
"Do simple things repeatedly, do repeated things seriously, and do serious things creatively!"——
I'm a third evil. I can call my third brother / third brother / third son. I'm a full stack developer who can write and fight. I'll see you next time!
reference resources:
[1] : small column: actual combat of SpringCloudAlibaba micro service
[2] : order design of e-commerce system
[3] : Spring Cloud Alibaba next generation microservice solution