使用Nacos、Open Feign、Gateway、Sentinel技术栈实现XX公司订单、库存、积分的案例开发,以下是服务调用关系
git代码:https://gitee.com/pet365/spring-cloud-goods
https://github.com/RainbowForest/e-commerce-microservices
https://awesomeopensource.com/project/RainbowForest/e-commerce-microservices
使用Nacos、Open Feign、Gateway、Sentinel技术栈实现XX公司订单、库存、积分的案例开发,以下是服务调用关系
技术栈:Nacos、Open Feign、Gateway、Sentinel技术栈
(二)数据库设计:
(1)订单表、订单明细表
(2)商品表
(3)积分表
(三)项目需求
(1)现订单增删改查除功能
(2)实现商品增删改查除功能
(3)实现积分增删改查除功能
(4)实现nacos配置中心
(5)实现网关用户认证功能
(6)实现对外提供接口API走网关功能
(7)实现内部服务调用功能
(8)Sentinel降级服务(制造异常情况实现降级)
(9)实现网关限流功能
/*
Navicat Premium Data Transfer
Source Server : 127.0.0.1
Source Server Type : MySQL
Source Server Version : 80022
Source Host : 127.0.0.1:3306
Source Schema : consumer_goods_order
Target Server Type : MySQL
Target Server Version : 80022
File Encoding : 65001
Date: 10/10/2023 21:51:03
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for goods_order
-- ----------------------------
DROP TABLE IF EXISTS `goods_order`;
CREATE TABLE `goods_order` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键,暂不考虑高并发问题',
`user_id` int NULL DEFAULT NULL COMMENT '用户id',
`price` decimal(10, 2) NULL DEFAULT NULL COMMENT '总价格',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for goods_order_detail
-- ----------------------------
DROP TABLE IF EXISTS `goods_order_detail`;
CREATE TABLE `goods_order_detail` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '订单明细表主键',
`order_id` int NULL DEFAULT NULL COMMENT '订单表的id',
`goods_id` int NULL DEFAULT NULL COMMENT '商品的id',
`nums` int NULL DEFAULT NULL COMMENT '数量',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
/*
Navicat Premium Data Transfer
Source Server : 127.0.0.1
Source Server Type : MySQL
Source Server Version : 80022
Source Host : 127.0.0.1:3306
Source Schema : consumer_goods_product
Target Server Type : MySQL
Target Server Version : 80022
File Encoding : 65001
Date: 10/10/2023 21:52:45
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for goods_sku
-- ----------------------------
DROP TABLE IF EXISTS `goods_sku`;
CREATE TABLE `goods_sku` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商品名',
`price` decimal(10, 2) NULL DEFAULT NULL COMMENT '价格',
`stock` int NULL DEFAULT NULL COMMENT '数量',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of goods_sku
-- ----------------------------
INSERT INTO `goods_sku` VALUES (1, 'iPhone 15 Pro Max 超视网膜 XDR 显示屏', 8999.00, 39);
SET FOREIGN_KEY_CHECKS = 1;
/*
Navicat Premium Data Transfer
Source Server : 127.0.0.1
Source Server Type : MySQL
Source Server Version : 80022
Source Host : 127.0.0.1:3306
Source Schema : consumer_goods_points
Target Server Type : MySQL
Target Server Version : 80022
File Encoding : 65001
Date: 10/10/2023 21:53:48
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for goods_point
-- ----------------------------
DROP TABLE IF EXISTS `goods_point`;
CREATE TABLE `goods_point` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` int NULL DEFAULT NULL COMMENT '对应用户的主键',
`point` decimal(10, 2) NULL DEFAULT NULL COMMENT '积分数量',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of goods_point
-- ----------------------------
INSERT INTO `goods_point` VALUES (1, 1, 10.89);
INSERT INTO `goods_point` VALUES (2, 1, 8999.00);
INSERT INTO `goods_point` VALUES (3, 1, 8999.00);
INSERT INTO `goods_point` VALUES (4, 1, 8999.00);
INSERT INTO `goods_point` VALUES (5, 1, 17998.00);
INSERT INTO `goods_point` VALUES (6, 1, 17998.00);
INSERT INTO `goods_point` VALUES (7, 1, 8999.00);
INSERT INTO `goods_point` VALUES (8, 1, 8999.00);
SET FOREIGN_KEY_CHECKS = 1;
内部服务使用Open Feign
下单调用商品服务减库存
下单调用积分服务加积分
下面是我用的token
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJhZG1pbiJ9.Gdsp9Fz9DTbekM7maxJVceuWZeEZlF0Ir0NuzHbE7kc
权限从redis中获取
①积分查询列表
②商品查询列表
③订单查询列表
④下单功能
进行配置
JMeter测试工具
http请求
线程数设置
sentinel中查看监控波形图
JMeter后台结果树
消峰填谷
采用均匀排除的策略
在积分微服务中,通过传的参数进行是否抛出异常
在调用积分微服务的订单order微服务中,设置feign的fallback
对于order调用的积分的请求资源进行熔断规则的设置
总体概览,多次调用触发了熔断降级,发送正常请求,次数处于熔断期间,因此也被降级。
使用Nacos、Open Feign、Gateway、Sentinel技术栈实现XX公司订单、库存、积分的案例开发,以下是服务调用关系