Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: update integrated-example doc #3309

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@ Enter `spring-cloud-alibaba-examples/integration-examplee` directory, Run the fo

Enter `spring-cloud-alibaba-examples/integration-example` directory, Run the following command in the terminal to `docker-compose -f ./docker-compose/docker-compose-env.yml down` to stop the running example component container.

> When the container starts, you can observe the startup process of the container through `docker-compose- f docker-compose-*.yml up`!
> When the container starts, you can observe the startup process of the container through `docker-compose- f docker-compose-*.yml up` !

## Experience Demo

After the preparation work is done, you can run the demo, mainly according to different usage scenarios, you can experience the user order (distributed transaction capability) and simulate the high traffic point (meltdown and limit the flow as well as the ability to cut the peak and fill the valley) respectively.

First, you need to start the `integrated-frontend` and `integrated-gateway` projects separately.

- The gateway module is the gateway for the entire best practice example.
- frontend is the simple front-end page for the best practice.

### Distributed Transaction Capabilities

#### Scenario Description
Expand All @@ -79,9 +72,7 @@ For the distributed transaction capability, we provide the scenario **where a us
- Deduct the account balance
- Generate order information to return a response

##### Start test

Start `integrated-storage`,`integrated-account`,`integrated-order` microservices respectively.
#### Start test

Visit `http://integrated-frontend:8080/order` to experience the corresponding scenario.

Expand Down Expand Up @@ -116,9 +107,7 @@ For service fusion limiting and peak and valley cutting in the context of high t
- Sentinel binds specified gateway routes on the gateway side for fusion degradation of services.
- RocketMQ performs traffic clipping, where the producer sends messages to RocketMQ under high traffic requests, while the consumer pulls and consumes through a configurable consumption rate, reducing the pressure of high traffic direct requests to the database to increase the number of likes requests.

#### Startup test

Start the `integrated-praise-provider` and `integrated-praise-consumer` modules separately.
#### Start test

- Sentinel service meltdown degradation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,44 @@

### 准备jar包

进入`spring-cloud-alibaba-examples`目录下,执行`mvn package`命令编译项目生成jar包,为后续Docker构建服务镜像做准备。
进入 `spring-cloud-alibaba-examples` 目录下,执行 `mvn package` 命令编译项目生成jar包,为后续Docker构建服务镜像做准备。

## 快速启动

### 组件启动

进入`spring-cloud-alibaba-examples/integrated-example`目录下,在终端中执行以下命令`docker-compose -f ./docker-compose/docker-compose-env.yml up -d`来快速部署运行example所需组件。
进入 `spring-cloud-alibaba-examples/integrated-example` 目录下,在终端中执行以下命令 `docker-compose -f ./docker-compose/docker-compose-env.yml up -d` 来快速部署运行example所需组件。

### 添加配置

docker-compose-env.yml文件运行成功之后,添加Nacos配置:

1. 进入`spring-cloud-alibaba-examples/integrated-example`目录下;
2. 在终端中执行`config-init/scripts/nacos-config-quick.sh`脚本文件。
1. 进入 `spring-cloud-alibaba-examples/integrated-example` 目录下;
2. 在终端中执行 `config-init/scripts/nacos-config-quick.sh` 脚本文件。

完成所有微服务配置的一键导入。

> 注意:windows操作系统可以通过`git bash`执行shell脚本文件完成配置导入。
> 注意:windows操作系统可以通过 `git bash` 执行shell脚本文件完成配置导入。

### 服务启动

进入`spring-cloud-alibaba-examples/integrated-example`目录下,在终端中执行以下命令`docker-compose -f ./docker-compose/docker-compose-service.yml up -d`来快速部署运行example所需服务。
进入 `spring-cloud-alibaba-examples/integrated-example` 目录下,在终端中执行以下命令 `docker-compose -f ./docker-compose/docker-compose-service.yml up -d` 来快速部署运行example所需服务。

## 停止所有容器

### 停止服务容器

进入`spring-cloud-alibaba-examples/integrated-example`目录下,在终端中执行以下命令`docker-compose -f ./docker-compose/docker-compose-service.yml down`来停止正在运行的example服务容器。
进入 `spring-cloud-alibaba-examples/integrated-example` 目录下,在终端中执行以下命令 `docker-compose -f ./docker-compose/docker-compose-service.yml down` 来停止正在运行的example服务容器。


### 停止组件容器

进入`spring-cloud-alibaba-examples/integrated-example`目录下,在终端中执行以下命令`docker-compose -f ./docker-compose/docker-compose-env.yml down`来停止正在运行的example组件容器。
进入 `spring-cloud-alibaba-examples/integrated-example` 目录下,在终端中执行以下命令 `docker-compose -f ./docker-compose/docker-compose-env.yml down` 来停止正在运行的example组件容器。

> 在容器启动时,可以通过`docker-compose -f docker-compose-*.yml up`观察容器的启动过程!
> 在容器启动时,可以通过 `docker-compose -f docker-compose-*.yml up` 观察容器的启动过程!

## 体验Demo

准备工作完成后可以运行 demo 示例,主要根据不同的使用场景,可以分别体验用户下单(分布式事务能力)以及模拟高流量点赞(熔断限流以及削峰填谷的能力)。

首先需要分别启动`integrated-frontend`以及`integrated-gateway`微服务应用。

- `integrated-gateway` 模块是整个最佳实践示例的网关。
- `integrated-frontend` 为最佳实践示例的简易前端页面。

### 分布式事务能力

#### 场景说明
Expand All @@ -80,11 +73,9 @@ docker-compose-env.yml文件运行成功之后,添加Nacos配置:
- 扣减账户余额
- 生成订单信息返回响应

##### 启动测试

分别启动`integrated-storage`,`integrated-account`,`integrated-order`三个微服务应用。
#### 启动测试

访问`http://integrated-frontend:8080/order` 来体验对应场景。
访问 `http://integrated-frontend:8080/order` 来体验对应场景。

直接点击下单按钮提交表单,应用模拟客户端向网关发送了一个创建订单的请求。

Expand All @@ -98,11 +89,11 @@ docker-compose-env.yml文件运行成功之后,添加Nacos配置:

而在前面的准备工作中,**初始化业务数据库表**的时候应用新建了一个用户,用户userId 为 admin,余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。

因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 1 号的库存个数(100-1=99),扣减 admin 用户的余额(3-2=1)
因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 1 号的库存个数100-1=99,扣减 admin 用户的余额3-2=1

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155429801.png)

如果再次请求相同的接口,同样是先扣减库存(99-1=98),但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。
如果再次请求相同的接口,同样是先扣减库存99-1=98,但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155436112.png)

Expand All @@ -119,25 +110,23 @@ docker-compose-env.yml文件运行成功之后,添加Nacos配置:

#### 启动测试

分别启动`integrated-praise-provider`以及`integrated-praise-consumer`模块。

- Sentinel 服务熔断降级

访问`http://integrated-frontend:8080/sentinel` 体验对应场景。
访问 `http://integrated-frontend:8080/sentinel` 体验对应场景。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155501290.png)

网关路由点赞服务的限流规则为 5,而在前端通过异步处理模拟了 10 次并发请求。

因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)
因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155755103.png)

- RocketMQ 进行流量削峰填谷

访问`http://integrated-frontend:8080/rocketmq` 体验对应场景。
访问 `http://integrated-frontend:8080/rocketmq` 体验对应场景。

由于之前在 Nacos 中配置了`integrated-praise-consumer`消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
由于之前在 Nacos 中配置了 `integrated-praise-consumer` 消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。

可以看到数据库中点赞的个数正在动态更新。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ helm uninstall integrated-example

##### 启动测试

访问`http://integrated-frontend:30080/order` 来体验对应场景。
访问 `http://integrated-frontend:30080/order` 来体验对应场景。

直接点击下单按钮提交表单,模拟客户端向网关发送了一个创建订单的请求。

Expand All @@ -66,11 +66,11 @@ helm uninstall integrated-example

而在 `integrated-mysql` 容器的初始化时,**初始化业务数据库表**的时候新建了一个用户,用户的userId为admin,余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。

因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 1 号的库存个数(100-1=99),扣减 admin 用户的余额(3-2=1)
因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 1 号的库存个数100-1=99,扣减 admin 用户的余额3-2=1

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143057730.png)

如果再次请求相同的接口,同样是先扣减库存(99-1=98),但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。
如果再次请求相同的接口,同样是先扣减库存99-1=98,但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143104810.png)

Expand All @@ -89,23 +89,23 @@ helm uninstall integrated-example

- Sentinel 服务熔断降级

访问`http://integrated-frontend:30080/sentinel` 体验对应场景。
访问 `http://integrated-frontend:30080/sentinel` 体验对应场景。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143120697.png)

网关路由点赞服务的限流规则为 5,而在前端通过异步处理模拟了 10 次并发请求。

因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)
因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143203773.png)

- RocketMQ 进行流量削峰填谷

访问`http://integrated-frontend:30080/rocketmq` 体验对应场景。
访问 `http://integrated-frontend:30080/rocketmq` 体验对应场景。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143342664.png)

由于之前在 Nacos 中配置了`integrated-praise-consumer`消费者模块的消费速率以及间隔,在点击按钮时应用将会模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
由于之前在 Nacos 中配置了 `integrated-praise-consumer` 消费者模块的消费速率以及间隔,在点击按钮时应用将会模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。

可以看到数据库中点赞的个数正在动态更新。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#### Nacos启动

为了便于 example 的演示,这里采用 Nacos 的`standalone`模式启动,进入到 Nacos 解压后的目录下,执行如下命令。
为了便于 example 的演示,这里采用 Nacos 的 `standalone` 模式启动,进入到 Nacos 解压后的目录下,执行如下命令。

```shell
#Linux/Mac环境
Expand All @@ -63,9 +63,9 @@ bash bin/startup.sh -m standalone

#### 新增配置文件

在批量导入配置之前,请先修改`spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml` 中的数据源配置**(用户名和密码)**。
在批量导入配置之前,请先修改 `spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml` 中的数据源配置**用户名和密码**。

之后运行`spring-cloud-alibaba-examples/integrated-example/config-init/scripts/nacos-config-quick.sh` 来完成所有微服务配置的一键导入。
之后运行 `spring-cloud-alibaba-examples/integrated-example/config-init/scripts/nacos-config-quick.sh` 来完成所有微服务配置的一键导入。

```shell
# linux
Expand Down Expand Up @@ -116,9 +116,9 @@ sh bin/mqbroker

## 运行 Demo 示例

准备工作完成后可以运行 demo 示例,主要根据不同的使用场景,可以分别体验用户下单(分布式事务能力)以及模拟高流量点赞(熔断限流以及削峰填谷的能力)
准备工作完成后可以运行 demo 示例,主要根据不同的使用场景,可以分别体验用户下单分布式事务能力以及模拟高流量点赞熔断限流以及削峰填谷的能力

首先需要分别启动`integrated-frontend`以及`integrated-gateway`微服务应用。
首先需要分别启动 `integrated-frontend` 以及 `integrated-gateway` 微服务应用。

- `integrated-gateway` 模块是整个最佳实践示例的网关。
- `integrated-frontend` 为最佳实践示例的简易前端页面。
Expand All @@ -135,9 +135,9 @@ sh bin/mqbroker

##### 启动测试

分别启动`integrated-storage`,`integrated-account`,`integrated-order`三个微服务应用。
分别启动 `integrated-storage``integrated-account``integrated-order` 三个微服务应用。

访问`http://integrated-frontend:8080/order` 来体验对应场景。
访问 `http://integrated-frontend:8080/order` 来体验对应场景。

直接点击下单按钮提交表单,应用模拟客户端向网关发送了一个创建订单的请求。

Expand All @@ -151,11 +151,11 @@ sh bin/mqbroker

而在前面的准备工作中,**初始化业务数据库表**的时候应用新建了一个用户,用户userId 为 admin,余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。

因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 1 号的库存个数(100-1=99),扣减 admin 用户的余额(3-2=1)
因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 1 号的库存个数100-1=99,扣减 admin 用户的余额3-2=1

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155429801.png)

如果再次请求相同的接口,同样是先扣减库存(99-1=98),但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。
如果再次请求相同的接口,同样是先扣减库存99-1=98,但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155436112.png)

Expand All @@ -172,25 +172,25 @@ sh bin/mqbroker

#### 启动测试

分别启动`integrated-praise-provider`以及`integrated-praise-consumer`模块。
分别启动 `integrated-praise-provider` 以及 `integrated-praise-consumer` 模块。

- Sentinel 服务熔断降级

访问`http://integrated-frontend:8080/sentinel` 体验对应场景。
访问 `http://integrated-frontend:8080/sentinel` 体验对应场景。

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155501290.png)

网关路由点赞服务的限流规则为 5,而在前端通过异步处理模拟了 10 次并发请求。

因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)
因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)

![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155755103.png)

- RocketMQ 进行流量削峰填谷

访问`http://integrated-frontend:8080/rocketmq` 体验对应场景。
访问 `http://integrated-frontend:8080/rocketmq` 体验对应场景。

由于之前在 Nacos 中配置了`integrated-praise-consumer`消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
由于之前在 Nacos 中配置了 `integrated-praise-consumer` 消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。

可以看到数据库中点赞的个数正在动态更新。
Expand Down
Loading