Merge pull request #2828 from TrevorLink/2.2.x-examples

feat: Helm installation for integrated exmaple
pull/2870/head^2
Steve Rao 2 years ago committed by GitHub
commit d14142eae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,3 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/integrated_account?useSSL=false&characterEncoding=utf8
url: jdbc:mysql://integrated-mysql:3306/integrated_account?useSSL=false&characterEncoding=utf8

@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/integrated_praise?useSSL=false&characterEncoding=utf8
url: jdbc:mysql://integrated-mysql:3306/integrated_praise?useSSL=false&characterEncoding=utf8
cloud:
stream:
bindings:
@ -10,7 +10,7 @@ spring:
group: praise-consumer-group-PRAISE-TOPIC-01
rocketmq:
binder:
name-server: localhost:9876
name-server: rocketmq:9876
bindings:
praise-input:
consumer:

@ -1,3 +1,3 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/integrated_order?useSSL=false&characterEncoding=utf8
url: jdbc:mysql://integrated-mysql:3306/integrated_order?useSSL=false&characterEncoding=utf8

@ -7,7 +7,7 @@ spring:
content-type: application/json
rocketmq:
binder:
name-server: localhost:9876
name-server: rocketmq:9876
bindings:
praise-output:
producer:

@ -1,3 +1,3 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/integrated_storage?useSSL=false&characterEncoding=utf8
url: jdbc:mysql://integrated-mysql:3306/integrated_storage?useSSL=false&characterEncoding=utf8

@ -1,2 +1,124 @@
# Spring Cloud Alibaba Containerized Deployment Best Practices | Docker-Compose Container Edition
Under Construction.....
# Spring Cloud Alibaba Containerized Deployment Best Practices | Kubernetes Helm-Chart Edition
## Preparation
This is the Spring Cloud Alibaba Best Practices Kubernetes deployment version, which requires you to prepare the following environment.
- Kubernetes (We recommend using Docker Desktop's built-in integrated Kubernetes environment for this experience.)
- Helm
If you don't have the above environment, please go to the official documentation to build the environment.
- [Helm Installation](https://helm.sh/zh/docs/intro/install/)
- [Kubernetes Docker Desktop Quick Installation](https://docs.docker.com/desktop/kubernetes/)
Here we expose the services of the Pod in Kubernetes to the outside world by means of NodePort, and configure the ip mapping of the Kubernetes cluster node before starting the test.
```sh
# Please adjust with the public ip of your K8S node
120.24.xxx.xxx integrated-frontend
120.24.xxx.xxx gateway-service
120.24.xxx.xxx integrated-mysql-web
120.24.xxx.xxx nacos-mysql-web
120.24.xxx.xxx nacos-svc
```
## Start the test
Go to the ``spring-cloud-alibaba-examples/integrated-example`` directory and execute the following command to deploy the application using Helm.
```shell
helm package helm-chart
helm install integrated-example integrated-example-1.0.0.tgz
```
With the above command we have completed the deployment of the best practice project via Helm with one click based on the Helm Chart documentation provided by the project.
You can check the deployment status of each container resource through the `kubectl` command provided by Kubernetes, and wait patiently for **all containers to finish starting** to experience the usage scenarios and capabilities of each component on the corresponding page.
If you want to stop the experience, enter the following command.
```shell
helm uninstall integrated-example
```
### Distributed Transaction Capabilities
#### Scenario Description
For the distributed transaction capability, we provide a scenario **where a user places an order to purchase goods** and after placing the order.
- First request the inventory module and deduct the inventory
- Deduct the account balance
- Generate order information to return a response
##### Start test
Visit `http://integrated-frontend:30080/order` to experience the corresponding scenario.
By clicking directly on the order button to submit the form, we simulate the client sending a request to the gateway to create an order.
- The user's userId is admin
- The user places an order with item number 1
- The number of items purchased in this order is 1
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143033445.png)
In this demo example, the unit price of each item is 2 for demonstration purposes.
While initializing the `integrated-mysql` container, **initializing the business database table** creates a new user userId = admin with a balance of $3; and a new item numbered 1 with 100 units in stock.
So by doing the above, we will create an order, deduct the number of items in stock corresponding to item number 1 (100-1=99), and deduct the balance of the admin user (3-2=1).
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143057730.png)
If the same interface is requested again, again the inventory is deducted first (99-1=98), but an exception is thrown because the admin user's balance is insufficient and is caught by Seata, which performs a two-stage commit of the distributed transaction and rolls back the transaction.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143104810.png)
You can see that the database still has 99 records in stock because of the rollback.
### Fused flow limiting, peak shaving capability
#### Scenario Description
For service fusion limiting and peak and valley cutting in the context of high traffic, we provide a scenario** where users make likes for products**. In this scenario, we provide two ways to deal with high traffic.
- 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
- Sentinel Service Meltdown Degradation
Visit `http://integrated-frontend:30080/sentinel` to experience the corresponding scenario.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143120697.png)
The Gateway routing point service has a flow limit rule of 5, while 10 concurrent requests are simulated on the front end through asynchronous processing.
Therefore, we can see that Sentinel performs a service fusion on the Gateway side to return the fallback to the client for the extra traffic, while the number of likes in the database is updated (+5).
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143203773.png)
- RocketMQ is performing peak and valley reduction
Visit `http://integrated-frontend:30080/rocketmq` to experience the corresponding scenario.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143342664.png)
Since we have previously configured the consumption rate and interval of the `integrated-consumer` consumer module in Nacos, we simulate 1000 like requests at the click of a button, and for 1000 like requests, `integrated_provider`
will deliver 1000 requests to the Broker, and the consumer module will consume them according to the configured consumption rate, and update the database with the product data of the likes, simulating the characteristics of RocketMQ to cut the peaks and fill the valleys under high traffic.
You can see that the number of likes in the database is being dynamically updated.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143352619.png)
## Other
This example **is just a selection of typical features for each component to serve the application scenario**.
Of course, there is more to each component than just what is demonstrated in the best practices, so if you are interested or want to go deeper, feel free to study the individual example documentation for each component.
- Nacos examples
- [Nacos config example](../../../nacos-example/nacos-config-example/readme.md)
- [Nacos discovery example](../../../nacos-example/nacos-discovery-example/readme.md)
- [Sentinel core example](../../../sentinel-example/sentinel-core-example/readme.md)
- [Seata example](../../../seata-example/readme.md)
- [RocketMQ example](../../rocketmq-example/readme.md)

@ -1,10 +1,10 @@
## Spring Cloud Alibaba Containerized Deployment Best Practices | Local Deployment Version
# Spring Cloud Alibaba Containerized Deployment Best Practices | Local Deployment Edition
## Preparation
### Environment declaration
### Environment Declaration
Before running the local example, you need to ensure that the following base environment is available locally. If you do not have a current environment locally, the following step-by-step build will demonstrate the build process.
Before running the local example, you need to ensure that the following base environment is available locally. If you do not have a current environment locally, the following step-by-step build will be done to demonstrate the build process.
- Nacos server
- Seata server
@ -13,51 +13,65 @@ Before running the local example, you need to ensure that the following base env
### Component Service Versions
To download and unpack the component versions of this project, please go to the release pages of the respective communities.
For each component version of this project, please go to the release page of each community to download and unpack.
- [Nacos: version 2.1.0](https://github.com/alibaba/nacos/releases)
- [Seata: version 1.5.1](https://github.com/seata/seata/releases)
- [RocketMQ: version 4.9.4](https://github.com/apache/rocketmq/releases)
- MySQL: version 5.7
### host configuration
To ensure that the code can start properly, please configure the local host mapping first, add the following mapping to the configuration file.
```sh
# for integrated-example
127.0.0.1 integrated-mysql
127.0.0.1 nacos-server
127.0.0.1 seata-server
127.0.0.1 rocketmq
127.0.0.1 gateway-service
127.0.0.1 integrated-frontend
```
### Database configuration
The following starts the local environment build preparation, before the database configuration starts, please make sure that the MySQL server is turned on.
Before you start the database configuration, please make sure the MySQL server is on.
#### Initializing Business Tables
#### Initialize business tables
For the first scenario, the orders, accounts and inventory microservices all need their own databases, while the second scenario simulating likes also needs a database to store the likes information.
For the first scenario, the order, account, and inventory microservices all need their own databases, while the second scenario simulates a database for storing like information as well.
Run the sql script `spring-cloud-alibaba-examples/integrated-example/sql/init.sql` to create the environment required for the business and the Seata-related tables in one click.
### Nacos configuration
### Nacos Configuration
Now that the database services are configured, you need to configure the Nacos configuration centre with all the microservice configuration files.
At this point, the database services are configured and you need to configure the Nacos configuration center for all the microservice configuration files.
#### Nacos startup
For the purpose of this example, Nacos is started in ``standalone'' mode. Go to the Nacos unpacked directory and execute the following command.
For the sake of example, here we use the ``standalone`` mode of Nacos, go to the unpacked directory of Nacos and execute the following command.
```sh
#Linux/Mac environment
sh bin/startup.sh -m standalone
#If you are in Ubuntu and the above command gives you an error saying [[symbol not found, you can run the following command
#If you are in Ubuntu and the above command gives you an error [[symbol not found, you can run the following command
bash bin/startup.sh -m standalone
#Win environment
. \bin\startup.cmd -m standalone
```
````
#### Adding configuration files
Before bulk importing the configuration, change the datasource configuration (username and password) in `integrated-example/config/datasource-config.yaml`.
Before bulk importing the configuration, please modify the datasource configuration (username and password) in `integrated-example/config/datasource-config.yaml`.
Afterwards, run `spring-cloud-alibaba-examples/integrated-example/scripts/nacos-config-quick.sh` to complete the one-click import of all microservice configurations.
After that, run `spring-cloud-alibaba-examples/integrated-example/scripts/nacos-config-quick.sh` to complete the one-click import of all microservice configurations.
### Seata configuration
### Seata Configuration
Once the Nacos service registry and configuration centre have been deployed, here is the configuration of the Seata server.
After the Nacos service registry and configuration center are deployed, here is the configuration of the Seata server.
Seata's db mode requires additional configuration of the database information and modification of the Seata Server configuration file, which has been merged in the new version compared to the old one.
Seata's db mode requires additional configuration of database information and modification of the Seata Server configuration file, and the configuration file has been merged in the new version compared to the old version, so for demonstration purposes, Seata Server is started in `file` mode on Seata standalone.
#### Start Seata Server
@ -72,7 +86,7 @@ bin\seata-server.bat
### RocketMQ configuration
Once the Seata service is started, you can start the RocketMQ NameServer and Broker services.
After the Seata service starts, you can start the RocketMQ NameServer and Broker services.
Go to the unpacked rocketmq directory after the release and execute the following command.
@ -94,98 +108,98 @@ sh bin/mqbroker
. \bin\mqbroker.cmd
```
## Run the demo
## Run the demo example
After the preparation work is done, you can run the demo to experience the user order (distributed transaction capability) and simulate the high traffic volume (meltdown limit and peak shaving capability) depending on different usage scenarios.
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.
The first step is to start the `integrated_frontend` and `integrated_gateway` projects respectively.
First, you need to start the `integrated_frontend` and `integrated_gateway` projects separately.
- The gateway module is the gateway to the entire best practice instance.
- frontend is the simple front-end page for the best practice.
### Distributed transaction capability
### Distributed Transaction Capabilities
#### scenario description
#### Scenario Description
For the distributed transaction capability, we provide a scenario **where a user places an order for goods** and after placing the order.
For the distributed transaction capability, we provide the scenario **where a user places an order for goods** and after placing the order.
- First request the inventory module and deduct the inventory
- Deducts the account balance
- Deduct the account balance
- Generate order information to return a response
##### start test
##### Start test
Start the `integrated_storage`, `integrated_account`, `integrated_order` microservices separately.
Start `integrated_storage`,`integrated_account`,`integrated_order` microservices respectively.
Visit `http://127.0.0.1:8080/order` to experience the corresponding scenario.
Visit `http://integrated-frontend:8080/order` to experience the corresponding scenario.
By clicking directly on the order button to submit the form, we simulate the client sending a request to the gateway to create an order.
By clicking the order button directly to submit the form, we simulate the client sending a request to the gateway to create an order.
- The user's userId is admin
- The user places an order for item number 1
- The item number of the user's order is 1
- The number of items purchased in this order is 1
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914153234414.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155416524.png)
In this demo, for demonstration purposes, the unit price of each item is 2.
In this demo example, the unit price of each item is 2 for demonstration purposes.
In the previous preparation, when **initialising the business database table** we created a new user userId = admin with a balance of $3 and a new item numbered 1 with 100 items in stock.
And in the previous preparation, **initialize business database table** we created a new user userId = admin with a balance of $3, and a new item numbered 1 with 100 units in stock.
So by doing the above, we create an order, deducting the number of units in stock for item number 1 (100-1=99) and deducting the balance of the admin user (3-2=1).
So by doing the above, we will create an order, deduct the number of items in stock corresponding to item number 1 (100-1=99), and deduct the balance of the admin user (3-2=1).
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914153126925.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155429801.png)
If the same interface is requested again, again the stock is deducted first (99-1=98), but an exception is thrown because the admin user's balance is insufficient and is caught by Seata, which performs a two-stage commit of the distributed transaction and rolls back the transaction.
If the same interface is requested again, again the inventory is deducted first (99-1=98), but an exception is thrown because the admin user's balance is insufficient and is caught by Seata, which performs a two-stage commit of the distributed transaction and rolls back the transaction.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914153313127.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155436112.png)
You can see that the database still has 99 records in stock because of the rollback.
### Melt limit, peak shaving capability
### Fused flow limiting, peak shaving capability
#### Scenario description
#### Scenario Description
For service fusion limiting in the context of high traffic and peak and valley reduction, we provide a scenario where **users like an item**. In this scenario, we provide two ways to deal with high traffic.
For service fusion limiting and peak and valley cutting in the context of high traffic, we provide a scenario **where users make likes for products**. In this scenario, we provide two ways to deal with high traffic.
- Sentinel binds a specified gateway route on the gateway side for fusion degradation of the service.
- RocketMQ performs traffic clipping, where the producer sends messages to RocketMQ during high traffic requests, while the consumer pulls and consumes at a configurable consumption rate, reducing the pressure of high traffic direct requests to the database to increase the number of likes requested.
- 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 tests
#### Startup test
Start the `integrated_provider` and `integrated_consumer` modules separately.
- Sentinel service meltdown downgrade
- Sentinel service meltdown degradation
Visit `http://127.0.0.1:8080/sentinel` to experience the corresponding scenario.
Visit `http://integrated-frontend:8080/sentinel` to experience the corresponding scenario.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155720469.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155501290.png)
The Gateway routing point service has a flow limit rule of 5, while 10 concurrent requests are simulated on the front-end through asynchronous processing.
The Gateway routing point service has a flow limit rule of 5, while 10 concurrent requests are simulated on the front end through asynchronous processing.
So you can see that Sentinel is fusing the service on the Gateway side to return a fallback to the client for the extra traffic, while the number of likes in the database is updated (+5).
Therefore, we can see that Sentinel performs a service fusion on the Gateway side to return the fallback to the client for the extra traffic, while the number of likes in the database is updated (+5).
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155755103.png)
- RocketMQ does peak and valley reduction
- RocketMQ is performing peak and valley reduction
Visit `http://127.0.0.1:8080/rocketmq` to experience the corresponding scenario.
Visit `http://integrated-frontend:8080/rocketmq` to experience the corresponding scenario.
As we have previously configured the consumption rate and interval of the `integrated-consumer` consumer module in Nacos, we simulate 1000 requests for likes at the click of a button, and for 1000 requests for likes, the `integrated_provider`
In the consumer module, we consume at the configured consumption rate and update the database with the product data, simulating the RocketMQ peak-shaving feature in heavy traffic.
Since we previously configured the consumption rate and interval of the `integrated-consumer` consumer module in Nacos, we simulate 1000 requests for likes at the click of a button, and the `integrated_provider`
will deliver 1000 requests to the Broker, and the consumer module will consume them according to the configured consumption rate, and update the database with the product data of the likes, simulating the characteristics of RocketMQ to cut the peaks and fill the valleys under high traffic.
You can see that the number of likes in the database is being dynamically updated.
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155815191.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016173604059.png)
## Other
This example **is just a selection of the typical features of each component to serve the application scenario**.
This example **is just a selection of typical features for each component to serve the application scenario**.
Of course, there is more to each component than what is demonstrated in the best practices, so if you are interested or want to go deeper, you are welcome to study the individual example documentation for each component.
If you are interested or want to go deeper, you are welcome to study the individual example documentation for each component.
- Nacos Examples
- [nacos-config-example](../../nacos-example/nacos-config-example/readme-zh.md)
- [nacos-discovery-example](../../nacos-example/nacos-discovery-example/readme-zh.md)
- [Sentinel-Core-Example](../../sentinel-example/sentinel-core-example/readme-zh.md)
- [Seata Examples](../../seata-example/readme-zh.md)
- [RocketMQ Example](../../rocketmq-example/readme-zh.md)
- Nacos examples
- [Nacos config example](../../../nacos-example/nacos-config-example/readme.md)
- [Nacos discovery example](../../../nacos-example/nacos-discovery-example/readme.md)
- [Sentinel core example](../../../sentinel-example/sentinel-core-example/readme.md)
- [Seata example](../../../seata-example/readme.md)
- [RocketMQ example](../../rocketmq-example/readme.md)

@ -1,2 +1,126 @@
# Spring Cloud Alibaba容器化部署最佳实践 | Kubernetes Helm-Chart 版本
建设中
## 准备工作
此版本为 Spring Cloud Alibaba 最佳实践 Kubernetes 部署版本,其中需要您准备如下的环境。
- Kubernetes建议使用 Docker Desktop 内置集成的 Kubernetes 环境进行体验。)
- Helm
如果您还未具备如上的环境,请移步至对应官方文档进行环境搭建。
- [Helm 安装](https://helm.sh/zh/docs/intro/install/)
- [Kubernetes Docker Desktop 快捷安装](https://docs.docker.com/desktop/kubernetes/)
在这里我们通过 NodePort 的方式来向外界暴露 Kubernetes 中 Pod 的服务,在启动测试前还需配置好 Kubernetes 集群节点的 ip 映射。
```sh
# 实际情况请结合您的 K8S 节点的公网 ip 进行调整
120.24.xxx.xxx integrated-frontend
120.24.xxx.xxx gateway-service
120.24.xxx.xxx integrated-mysql-web
120.24.xxx.xxx nacos-mysql-web
120.24.xxx.xxx nacos-svc
```
## 启动测试
进入到 `spring-cloud-alibaba-examples/integrated-example` 目录下,执行如下命令利用 Helm 部署应用程序。
```shell
helm package helm-chart
helm install integrated-example integrated-example-1.0.0.tgz
```
通过上述命令我们根据项目提供的 Helm Chart 文档通过 Helm 一键完成了最佳实践项目的部署。
可以通过 Kubernetes 提供的 `kubectl` 命令查看各容器资源部署的情况,耐心等待**所有容器完成启动后**即可到对应页面体验各个组件使用场景及能力。
如果您想停止体验,输入如下命令。
```shell
helm uninstall integrated-example
```
### 分布式事务能力
#### 场景说明
针对分布式事务能力,我们提供了**用户下单购买货物的场景**,下单后:
- 先请求库存模块,扣减库存
- 扣减账户余额
- 生成订单信息返回响应
##### 启动测试
访问`http://integrated-frontend:30080/order` 来体验对应场景。
直接点击下单按钮提交表单,我们模拟客户端向网关发送了一个创建订单的请求。
- 用户的 userId 为 admin
- 用户下单的商品编号为1号
- 此次订单购买的商品个数为1个
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143033445.png)
在本 demo 示例中为了便于演示每件商品的单价都为2。
而在 `integrated-mysql` 容器的初始化时,**初始化业务数据库表**的时候新建了一个用户 userId = admin余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。
因此通过上述的操作,我们会创建一个订单,扣减对应商品编号为 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 捕获,执行分布式事务二阶段提交,回滚事务。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143104810.png)
可以看到数据库中库存的记录因为回滚之后仍然为 99 件。
### 熔断限流,削峰填谷能力
#### 场景说明
针对大流量背景下的服务熔断限流,削峰天谷,我们提供了**用户为商品进行点赞的场景**。在此场景下,我们提供了两种应对大流量的处理方式。
- Sentinel 在网关侧绑定指定网关路由进行服务的熔断降级。
- RocketMQ 进行流量削峰填谷,在大流量请求下,生产者向 RocketMQ 发送消息,而消费者则通过可配置的消费速率进行拉取消费,减少大流量直接请求数据库增加点赞请求的压力。
#### 启动测试
- Sentinel 服务熔断降级
访问`http://integrated-frontend:30080/sentinel` 体验对应场景。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143120697.png)
网关路由点赞服务的限流规则为 5而在前端通过异步处理模拟了 10 次并发请求。
因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143203773.png)
- RocketMQ 进行流量削峰填谷
访问`http://integrated-frontend:30080/rocketmq` 体验对应场景。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143342664.png)
由于我们之前在 Nacos 中配置了`integrated-consumer`消费者模块的消费速率以及间隔,在点击按钮时我们模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated_provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。
可以看到数据库中点赞的个数正在动态更新。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143352619.png)
## 其他
本示例**仅是针对各个组件选取出了较为典型的功能特性来服务应用场景**。
当然各个组件的功能特性不仅仅只包含最佳实践中演示的这些,如果您感兴趣或是想要深入了解,欢迎学习各个组件的独立 example 相关文档。
- Nacos examples
- [Nacos config example](../../../nacos-example/nacos-config-example/readme-zh.md)
- [Nacos discovery example](../../../nacos-example/nacos-discovery-example/readme-zh.md)
- [Sentinel core example](../../../sentinel-example/sentinel-core-example/readme-zh.md)
- [Seata example](../../../seata-example/readme-zh.md)
- [RocketMQ example](../../../rocketmq-example/readme-zh.md)

@ -20,9 +20,22 @@
- [RocketMQ: 4.9.4 版本](https://github.com/apache/rocketmq/releases)
- MySQL: 5.7 版本
### host配置
为了保证代码可以正常启动,请先配置好本机的 host 映射,在配置文件中新增如下的映射。
```sh
# for integrated-example
127.0.0.1 integrated-mysql
127.0.0.1 nacos-server
127.0.0.1 seata-server
127.0.0.1 rocketmq
127.0.0.1 gateway-service
127.0.0.1 integrated-frontend
```
### 数据库配置
下面开始本地环境搭建准备在数据库配置开始之前请确保MySQL的服务端开启。
下面开始本地环境搭建准备,在数据库配置开始之前,请确保 MySQL 的服务端开启。
#### 初始化业务表
@ -117,7 +130,7 @@ sh bin/mqbroker
分别启动`integrated_storage`,`integrated_account`,`integrated_order`三个微服务。
访问`http://127.0.0.1:8080/order` 来体验对应场景。
访问`http://integrated-frontend:8080/order` 来体验对应场景。
直接点击下单按钮提交表单,我们模拟客户端向网关发送了一个创建订单的请求。
@ -125,7 +138,7 @@ sh bin/mqbroker
- 用户下单的商品编号为1号
- 此次订单购买的商品个数为1个
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914153234414.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155416524.png)
在本 demo 示例中为了便于演示每件商品的单价都为2。
@ -133,11 +146,11 @@ sh bin/mqbroker
因此通过上述的操作,我们会创建一个订单,扣减对应商品编号为 1 号的库存个数(100-1=99),扣减 admin 用户的余额(3-2=1)。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914153126925.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155429801.png)
如果再次请求相同的接口,同样是先扣减库存(99-1=98),但是会因为 admin 用户余额不足而抛出异常,并被 Seata 捕获,执行分布式事务二阶段提交,回滚事务。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914153313127.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155436112.png)
可以看到数据库中库存的记录因为回滚之后仍然为 99 件。
@ -156,9 +169,9 @@ sh bin/mqbroker
- Sentinel 服务熔断降级
访问`http://127.0.0.1:8080/sentinel` 体验对应场景。
访问`http://integrated-frontend:8080/sentinel` 体验对应场景。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155720469.png)
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155501290.png)
网关路由点赞服务的限流规则为 5而在前端通过异步处理模拟了 10 次并发请求。
@ -168,14 +181,14 @@ sh bin/mqbroker
- RocketMQ 进行流量削峰填谷
访问`http://127.0.0.1:8080/rocketmq` 体验对应场景。
访问`http://integrated-frontend:8080/rocketmq` 体验对应场景。
由于我们之前在 Nacos 中配置了`integrated-consumer`消费者模块的消费速率以及间隔,在点击按钮时我们模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated_provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。
可以看到数据库中点赞的个数正在动态更新。
![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155815191.png)
![image-20221016173604059](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016173604059.png)
## 其他
@ -183,9 +196,9 @@ sh bin/mqbroker
当然各个组件的功能特性不仅仅只包含最佳实践中演示的这些,如果您感兴趣或是想要深入了解,欢迎学习各个组件的独立 example 相关文档。
- Nacos Examples
- [nacos-config-example](../../nacos-example/nacos-config-example/readme-zh.md)
- [nacos-discovery-example](../../nacos-example/nacos-discovery-example/readme-zh.md)
- [Sentinel-Core-Example](../../sentinel-example/sentinel-core-example/readme-zh.md)
- [Seata Examples](../../seata-example/readme-zh.md)
- [RocketMQ Example](../../rocketmq-example/readme-zh.md)
- Nacos examples
- [Nacos config example](../../../nacos-example/nacos-config-example/readme-zh.md)
- [Nacos discovery example](../../../nacos-example/nacos-discovery-example/readme-zh.md)
- [Sentinel core example](../../../sentinel-example/sentinel-core-example/readme-zh.md)
- [Seata example](../../../seata-example/readme-zh.md)
- [RocketMQ example](../../../rocketmq-example/readme-zh.md)

@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: Spring Cloud Alibaba Best Practice Example
name: integrated-example
version: 1.0.0

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-account
spec:
replicas: 1
selector:
matchLabels:
app: integrated-account
template:
metadata:
labels:
appName: integrated-account
app: integrated-account
spec:
containers:
- name: integrated-account
image: "{{ .Values.image.repository }}integrated-account"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 8012

@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
name: integrated-frontend
labels:
app: integrated-frontend
spec:
type: NodePort
ports:
- port: 8080
name: web
targetPort: 8080
nodePort: 30080
selector:
app: integrated-frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-frontend
spec:
replicas: 1
selector:
matchLabels:
app: integrated-frontend
template:
metadata:
labels:
appName: integrated-frontend
app: integrated-frontend
spec:
containers:
- name: integrated-frontend
image: "{{ .Values.image.repository }}integrated-frontend"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 8080

@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
name: gateway-service
labels:
app: integrated-gateway
spec:
type: NodePort
ports:
- port: 30010
name: server
targetPort: 30010
nodePort: 30010
selector:
app: integrated-gateway
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-gateway
spec:
replicas: 1
selector:
matchLabels:
app: integrated-gateway
template:
metadata:
labels:
appName: integrated-gateway
app: integrated-gateway
spec:
containers:
- name: integrated-gateway
image: "{{ .Values.image.repository }}integrated-gateway"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 30010

@ -0,0 +1,53 @@
apiVersion: v1
kind: Service
metadata:
name: integrated-mysql-web
spec:
ports:
- name: integrated-mysql-port
protocol: TCP
port: 3306
targetPort: 3306
nodePort: 30306
type: NodePort
selector:
app: integrated-mysql
---
apiVersion: v1
kind: Service
metadata:
name: integrated-mysql
labels:
app: integrated-mysql
spec:
type: ClusterIP
ports:
- port: 3306
name: server
selector:
app: integrated-mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-mysql
spec:
selector:
matchLabels:
app: integrated-mysql
replicas: 1
template:
metadata:
labels:
app: integrated-mysql
spec:
containers:
- name: integrated-mysql
image: "{{ .Values.image.repository }}integrated-mysql"
imagePullPolicy: Always
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
ports:
- containerPort: 3306
protocol: TCP

@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nacos-mysql
labels:
name: nacos-mysql
spec:
replicas: 1
selector:
matchLabels:
name: nacos-mysql
template:
metadata:
labels:
name: nacos-mysql
spec:
containers:
- name: mysql
image: registry.cn-hangzhou.aliyuncs.com/sca-community/integrated-nacos-mysql
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
- name: MYSQL_DATABASE
value: "nacos_config"
- name: MYSQL_USER
value: "nacos"
- name: MYSQL_PASSWORD
value: "nacos"
---
apiVersion: v1
kind: Service
metadata:
name: nacos-mysql
labels:
name: nacos-mysql
spec:
ports:
- port: 3307
targetPort: 3306
selector:
name: nacos-mysql
---
apiVersion: v1
kind: Service
metadata:
name: nacos-mysql-web
spec:
ports:
- name: nacos-mysql-port
protocol: TCP
port: 3307
targetPort: 3306
nodePort: 30307
type: NodePort
selector:
name: nacos-mysql

@ -0,0 +1,126 @@
---
apiVersion: v1
kind: Service
metadata:
name: nacos-svc
labels:
app: nacos-svc
spec:
type: NodePort
ports:
- port: 8848
name: server
targetPort: 8848
nodePort: 30848
selector:
app: nacos-standalone
---
apiVersion: v1
kind: Service
metadata:
name: nacos-server
labels:
app: nacos-server
spec:
type: ClusterIP
ports:
- port: 8848
name: server
targetPort: 8848
- port: 9848
name: client-rpc
targetPort: 9848
- port: 9849
name: raft-rpc
targetPort: 9849
- port: 7848
name: old-raft-rpc
targetPort: 7848
selector:
app: nacos-standalone
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "nacos-mysql"
mysql.db.name: "nacos_config"
mysql.port: "3307"
mysql.user: "nacos"
mysql.password: "nacos"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nacos-standalone
spec:
replicas: 1
template:
metadata:
labels:
app: nacos-standalone
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- nacos-standalone
topologyKey: "kubernetes.io/hostname"
containers:
- name: local-nacos
imagePullPolicy: Always
image: registry.cn-hangzhou.aliyuncs.com/sca-community/nacos-server
ports:
- containerPort: 8848
name: client
- containerPort: 9848
name: client-rpc
- containerPort: 9849
name: raft-rpc
- containerPort: 7848
name: old-raft-rpc
env:
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.db.name
- name: MYSQL_SERVICE_PORT
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.port
- name: MYSQL_SERVICE_USER
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.user
- name: MYSQL_SERVICE_PASSWORD
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: MODE
value: "standalone"
- name: NACOS_SERVER_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
selector:
matchLabels:
app: nacos-standalone

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-order
spec:
replicas: 1
selector:
matchLabels:
app: integrated-order
template:
metadata:
labels:
appName: integrated-order
app: integrated-order
spec:
containers:
- name: integrated-order
image: "{{ .Values.image.repository }}integrated-order"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 8013

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-praise-consumer
spec:
replicas: 1
selector:
matchLabels:
app: integrated-praise-consumer
template:
metadata:
labels:
appName: integrated-praise-consumer
app: integrated-praise-consumer
spec:
containers:
- name: integrated-praise-consumer
image: "{{ .Values.image.repository }}integrated-praise-consumer"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 8014

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-praise-provider
spec:
replicas: 1
selector:
matchLabels:
app: integrated-praise-provider
template:
metadata:
labels:
appName: integrated-praise-provider
app: integrated-praise-provider
spec:
containers:
- name: integrated-praise-provider
image: "{{ .Values.image.repository }}integrated-praise-provider"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 8015

@ -0,0 +1,65 @@
apiVersion: v1
kind: Service
metadata:
name: rocketmq
spec:
ports:
- port: 9876
protocol: TCP
targetPort: 9876
selector:
app: mqnamesrv
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mqnamesrv
spec:
serviceName: mqnamesrv
replicas: 1
selector:
matchLabels:
app: mqnamesrv
template:
metadata:
labels:
app: mqnamesrv
spec:
containers:
- name: mqnamesrv
image: registry.cn-hangzhou.aliyuncs.com/sca-community/rocketmq-server
command: ["sh","/usr/local/rocketmq-4.8.0/bin/mqnamesrv"]
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9876
protocol: TCP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mqbroker
spec:
serviceName: mqbroker
replicas: 1
selector:
matchLabels:
app: mqbroker
template:
metadata:
labels:
app: mqbroker
spec:
containers:
- name: mqbroker
image: registry.cn-hangzhou.aliyuncs.com/sca-community/rocketmq-server
command: ["sh","/usr/local/rocketmq-4.8.0/bin/mqbroker", "-n","rocketmq:9876"]
imagePullPolicy: IfNotPresent
env:
- name: JAVA_OPT
value: "-server -XX:ParallelGCThreads=1 -Xms1g -Xmx1g -Xmn512m"
ports:
- containerPort: 10909
- containerPort: 10911
resources:
requests:
memory: 128Mi

@ -0,0 +1,43 @@
apiVersion: v1
kind: Service
metadata:
name: seata-server
labels:
k8s-app: seata-server
spec:
type: ClusterIP
ports:
- port: 8091
name: server
selector:
k8s-app: seata-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: seata-server
labels:
k8s-app: seata-server
spec:
replicas: 1
selector:
matchLabels:
k8s-app: seata-server
template:
metadata:
labels:
k8s-app: seata-server
spec:
containers:
- name: seata-server
image: registry.cn-hangzhou.aliyuncs.com/sca-community/seata-server
imagePullPolicy: IfNotPresent
env:
- name: SEATA_PORT
value: "8091"
- name: STORE_MODE
value: file
ports:
- name: http
containerPort: 8091
protocol: TCP

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrated-storage
spec:
replicas: 1
selector:
matchLabels:
app: integrated-storage
template:
metadata:
labels:
appName: integrated-storage
app: integrated-storage
spec:
containers:
- name: integrated-storage
image: "{{ .Values.image.repository }}integrated-storage"
imagePullPolicy: Always
ports:
- name: http-port
containerPort: 8011

@ -0,0 +1,2 @@
image:
repository: registry.cn-hangzhou.aliyuncs.com/sca-community/

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-account-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8012
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -7,12 +7,15 @@ spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
server-addr: nacos-server:8848
group: integrated-example
config:
server-addr: localhost:8848
server-addr: nacos-server:8848
file-extension: yaml
group: integrated-example
shared-dataids: datasorce-config.yaml
shared-configs[0]:
dataid: datasource-config.yaml
group: integrated-example
seata:
application-id: ${spring.application.name}
@ -21,4 +24,4 @@ seata:
vgroup-mapping:
integrated-account-group: default
grouplist:
default: localhost:8091
default: seata-server:8091

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-frontend-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8080
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -34,57 +34,66 @@
var userId = $("#userId").val();
var commodityCode = $("#commodityCode").val();
$.ajax({
url: "http://localhost:8010/storage/",
url: "http://gateway-service:30010/storage/",
type: "get",
dataType: "json",
data: "commodityCode=" + commodityCode,
async:false,
success: function (res) {
$('#orderResultSection').append(`<p> 执行分布式业务前商品库存: ${res.data} </p>`);
$('#orderResultSection').append(`<p> [${getDateTime()}] 执行分布式业务前商品库存: ${res.data} </p>`);
}
});
$.ajax({
url: "http://localhost:8010/account/",
url: "http://gateway-service:30010/account/",
type: "get",
dataType: "json",
data: "userId=" + userId,
async:false,
success: function (res) {
$('#orderResultSection').append(`<p> 执行分布式业务前账户余额: ${res.data}</p>`);
$('#orderResultSection').append(`<p> [${getDateTime()}] 执行分布式业务前账户余额: ${res.data}</p>`);
}
});
$.ajax({
type: "POST",
url: "http://localhost:8010/order/create",
url: "http://gateway-service:30010/order/create",
data: $('#orderForm').serialize(),
dataType: 'json',
async:false,
success: function (res) {
$('#orderResultSection').append(`<p> ${res.message} </p>`);
$('#orderResultSection').append(`<p> [${getDateTime()}] ${res.message} </p>`);
$.ajax({
url: "http://localhost:8010/storage/",
url: "http://gateway-service:30010/storage/",
type: "get",
dataType: "json",
data: "commodityCode=" + commodityCode,
async:false,
success: function (res) {
$('#orderResultSection').append(`<p> 执行分布式业务后商品库存: ${res.data}</p>`);
$('#orderResultSection').append(`<p> [${getDateTime()}] 执行分布式业务后商品库存: ${res.data}</p>`);
}
});
$.ajax({
url: "http://localhost:8010/account/",
url: "http://gateway-service:30010/account/",
type: "get",
dataType: "json",
data: "userId=" + userId,
async:false,
success: function (res) {
$('#orderResultSection').append(`<p> 执行分布式业务后账户余额: ${res.data}</p>`);
$('#orderResultSection').append(`<p> [${getDateTime()}] 执行分布式业务后账户余额: ${res.data}</p>`);
}
});
}
});
});
const getDateTime = () => {
const myDate = new Date;
const year = myDate.getFullYear();
const month = myDate.getMonth() + 1;
const date = myDate.getDate();
const hours = myDate.getHours();
const minutes = myDate.getMinutes();
const seconds = myDate.getSeconds();
return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
};
</script>
</body>

@ -31,13 +31,13 @@
function queryRes() {
$.ajax({
url: "http://localhost:8010/praise/query",
url: "http://gateway-service:30010/praise/query",
type: "get",
dataType: "json",
data: "itemId=" + $('#itemId').val(),
success: function (res) {
console.log("准备查询此时count=" + count)
$('#rocketmqResultSection').append(`<p> 点赞数: ${res} </p>`);
$('#rocketmqResultSection').append(`<p> [${getDateTime()}] 点赞数: ${res} </p>`);
}
})
}
@ -48,7 +48,7 @@
for (let i = 0; i < 1000; i++) {
$.ajax({
url: "http://localhost:8010/praise/rocketmq",
url: "http://gateway-service:30010/praise/rocketmq",
type: "get",
dataType: "json",
data: "itemId=" + itemId,

@ -23,40 +23,40 @@
$('#sentinelResultSection').empty();
var itemId = $('#itemId').val();
$.ajax({
url: "http://localhost:8010/praise/query",
url: "http://gateway-service:30010/praise/query",
type: "get",
dataType: "json",
data: "itemId=" + itemId,
async: false,
success: function (res) {
$('#sentinelResultSection').append(`<p> 点赞前的点赞数: ${res} </p>`);
$('#sentinelResultSection').append(`<p> [${getDateTime()}] 点赞前的点赞数: ${res} </p>`);
}
});
for (let i = 0; i < 10; i++) {
$.ajax({
url: "http://localhost:8010/praise/sentinel",
url: "http://gateway-service:30010/praise/sentinel",
type: "get",
dataType: "json",
data: "itemId=" + itemId,
success: function (res) {
console.log(res)
$('#sentinelResultSection').append(`<p> ${getDateTime()}: ${res}</p>`);
$('#sentinelResultSection').append(`<p> [${getDateTime()}] ${getDateTime()}: ${res}</p>`);
},
error: function (res) {
console.log(res)
$('#sentinelResultSection').append(`<p> ${getDateTime()}: 请求失败,接口被限流 </p>`);
$('#sentinelResultSection').append(`<p> [${getDateTime()}]: 请求失败,接口被限流 </p>`);
}
});
}
timeoutid = setTimeout(queryRes, 1000);
function queryRes() {
$.ajax({
url: "http://localhost:8010/praise/query",
url: "http://gateway-service:30010/praise/query",
type: "get",
dataType: "json",
data: "itemId=" + $('#itemId').val(),
success: function (res) {
$('#sentinelResultSection').append(`<p> 点赞后的点赞数: ${res} </p>`);
$('#sentinelResultSection').append(`<p> [${getDateTime()}] 点赞后的点赞数: ${res} </p>`);
}
})
}

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-gateway-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 30010
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -1,13 +1,14 @@
server:
port: 8010
port: 30010
spring:
application:
name: integrated-gateway
cloud:
nacos:
discovery:
server-addr: localhost:8848
server-addr: nacos-server:8848
group: integrated-example
config:
server-addr: localhost:8848
server-addr: nacos-server:8848
file-extension: yaml
group: integrated-example

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-order-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8013
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -7,12 +7,15 @@ spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
server-addr: nacos-server:8848
group: integrated-example
config:
server-addr: localhost:8848
server-addr: nacos-server:8848
file-extension: yaml
group: integrated-example
shared-dataids: datasorce-config.yaml
shared-configs[0]:
dataid: datasource-config.yaml
group: integrated-example
seata:
application-id: ${spring.application.name}
@ -21,4 +24,4 @@ seata:
vgroup-mapping:
integrated-order-group: default
grouplist:
default: localhost:8091
default: seata-server:8091

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-praise-consumer-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8014
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -5,11 +5,13 @@ spring:
nacos:
config:
file-extension: yaml
server-addr: localhost:8848
shared-configs[0]:
dataId: datasorce-config.yaml
server-addr: nacos-server:8848
group: integrated-example
shared-configs[0]:
dataid: datasource-config.yaml
group: integrated-example
discovery:
server-addr: localhost:8848
server-addr: nacos-server:8848
group: integrated-example
server:
port: 8014

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-praise-provider-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8015
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -5,7 +5,10 @@ spring:
nacos:
config:
file-extension: yaml
server-addr: localhost:8848
server-addr: nacos-server:8848
group: integrated-example
discovery:
server-addr: nacos-server:8848
group: integrated-example
server:
port: 8015

@ -0,0 +1,5 @@
FROM openjdk:8
ADD /target/integrated-storage-2.2.9-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8011
ENTRYPOINT ["java", "-jar","/app.jar"]

@ -7,12 +7,15 @@ spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
server-addr: nacos-server:8848
group: integrated-example
config:
server-addr: localhost:8848
server-addr: nacos-server:8848
file-extension: yaml
group: integrated-example
shared-dataids: datasorce-config.yaml
shared-configs[0]:
dataid: datasource-config.yaml
group: integrated-example
seata:
application-id: ${spring.application.name}
@ -21,4 +24,4 @@ seata:
vgroup-mapping:
integrated-storage-group: default
grouplist:
default: localhost:8091
default: seata-server:8091

@ -1,5 +1,4 @@
#!/bin/sh
groupId="integrated-example"
echo "Nacos auto config started"
datasourceConfig=$(cat ../config/datasource-config.yaml)
storageConfig=$(cat ../config/integrated-storage.yaml)
@ -8,11 +7,12 @@ orderConfig=$(cat ../config/integrated-order.yaml)
gatewayConfig=$(cat ../config/integrated-gateway.yaml)
providerConfig=$(cat ../config/integrated-provider.yaml)
consumerConfig=$(cat ../config/integrated-consumer.yaml)
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=datasource-config.yaml&group=${groupId}&content=${datasourceConfig}"
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=integrated-storage.yaml&group=${groupId}&content=${storageConfig}"
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=integrated-account.yaml&group=${groupId}&content=${accountConfig}"
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=integrated-order.yaml&group=${groupId}&content=${orderConfig}"
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=integrated-gateway.yaml&group=${groupId}&content=${gatewayConfig}"
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=integrated-provider.yaml&group=${groupId}&content=${providerConfig}"
curl -X POST "127.0.0.1:8848/nacos/v1/cs/configs" -d "dataId=integrated-consumer.yaml&group=${groupId}&content=${consumerConfig}"
groupId="integrated-example"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=datasource-config.yaml&group=${groupId}&content=${datasourceConfig}"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=integrated-storage.yaml&group=${groupId}&content=${storageConfig}"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=integrated-account.yaml&group=${groupId}&content=${accountConfig}"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=integrated-order.yaml&group=${groupId}&content=${orderConfig}"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=integrated-gateway.yaml&group=${groupId}&content=${gatewayConfig}"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=integrated-provider.yaml&group=${groupId}&content=${providerConfig}"
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" -d "dataId=integrated-consumer.yaml&group=${groupId}&content=${consumerConfig}"
echo "Nacos config pushed successfully finished"
Loading…
Cancel
Save