To ensure that the code can start properly, please configure the local host mapping first, add the following mapping to the configuration file.
```shell
# 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
```
### Preparing jar packages
Go to the `spring-cloud-alibaba-examples` directory and run the `mvn package` command to compile the project and generate the jar package, so as to prepare for the subsequent construction of the docker service image.
## Quickly start
### Component start
Enter `spring-cloud-alibaba-examples/integration-example` directory, run the following command in the terminal to quickly deploy the components required to run example: `docker-compose -f ./docker-compose/docker-compose-env.yml up -d`.
### Add configuration
After docker-compose-env.yml is run successfully, add the Nacos configuration:
- Enter `spring-cloud-alibaba-examples/integration-example` directory;
- Execute the `config-init/scripts/nacos-config-quick.sh` script file in the terminal.
The one-click import of all micro-service configurations is complete.
> Note: windows operating systems can use `git bash` to execute shell script files to complete the configuration import.
### Service start
Enter `spring-cloud-alibaba-examples/integration-example` directory, Run the following command in the terminal to quickly deploy the services required for running example: `docker-compose -f ./docker-compose/docker-compose-service.yml up -d`.
## Stop all containers
### Stops the service container
Enter `spring-cloud-alibaba-examples/integration-examplee` directory, Run the following command in the terminal to `docker-compose -f ./docker-compose/docker-compose-service.yml down` to stop the running example service container.
### Stops the component container
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`!
## 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
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
In this demo example, the unit price of each item is 2 for demonstration purposes.
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 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).
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.
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
Start the `integrated-praise-provider` and `integrated-praise-consumer` modules separately.
- Sentinel service meltdown degradation
Visit `http://integrated-frontend:8080/sentinel` to experience the corresponding scenario.
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).
- RocketMQ is performing peak and valley reduction
Visit `http://integrated-frontend:8080/rocketmq` to experience the corresponding scenario.
Since we previously configured the consumption rate and interval of the `integrated-praise-consumer` consumer module in Nacos, we simulate 1000 requests for likes at the click of a button, and the `integrated-praise-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.
This is the Spring Cloud Alibaba Best Practices Kubernetes deployment version, which requires you to prepare the following environment.
This is the Spring Cloud Alibaba (hereinafter referred to as SCA) 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.)
- Kubernetes (We recommend using Docker Desktop's built-in integrated Kubernetes environment for this experience.)
- Helm
- Helm
If you don't have the above environment, please go to the official documentation to build the environment.
If the test machine does not already have the above environment, please go to the official documentation to build the environment.
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.
Here 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
```shell
# Please adjust with the public ip of your K8S node
# Please adjust with the public ip of your K8S node
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.
By running the above command, quickly deploy the best practice example through Helm according to the Helm Chart documentation provided by the SCA community.
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.
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.
For the distributed transaction capability, we provide a scenario **where a user places an order to purchase goods** and after placing the order.
For the distributed transaction capability, SCA community 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
- First request the inventory module and deduct the inventory
- Deduct the account balance
- Deduct the account balance
@ -53,7 +53,7 @@ For the distributed transaction capability, we provide a scenario **where a user
Visit `http://integrated-frontend:30080/order` to experience the corresponding scenario.
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.
By clicking directly on the order button to submit the form, simulate the client sending a request to the gateway to create an order.
- The user's userId is admin
- The user's userId is admin
- The user places an order with item number 1
- The user places an order with item number 1
@ -63,8 +63,8 @@ By clicking directly on the order button to submit the form, we simulate the cli
In this demo example, the unit price of each item is 2 for demonstration purposes.
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.
While initializing the `integrated-mysql` container, **initializing the business database table** creates a new user, the user's userId is 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).
So by doing the above, application 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).
@ -78,7 +78,7 @@ You can see that the database still has 99 records in stock because of the rollb
#### Scenario Description
#### 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.
For service fusion limiting and peak and valley cutting in the context of high traffic, SCA community 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.
- 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.
- 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.
@ -103,7 +103,7 @@ Visit `http://integrated-frontend:30080/rocketmq` to experience the correspondin
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`
Since the consumption rate and interval of the `integrated-praise-consumer` consumer module is configured in Nacos before, the application will simulate 1000 "like" requests when clicking the button, `integrated-praise-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.
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.
You can see that the number of likes in the database is being dynamically updated.
@ -114,7 +114,7 @@ You can see that the number of likes in the database is being dynamically update
This example **is just a selection of typical features for 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 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.
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 read the individual example documentation for each component.
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.
Before running the local example, you need to ensure that the local machine has the following basic environment. If you do not have the current local environment, the following steps to demonstrate the construction process.
You can also quickly launch the component through the docker-compose file provided by the Spring Cloud Alibaba (SCA) community.
- Nacos server
- Nacos server
- Seata server
- Seata server
@ -13,18 +14,18 @@ Before running the local example, you need to ensure that the following base env
### Component Service Versions
### Component Service Versions
For each component version of this project, please go to the release page of each community to download and unpack.
For each component version of this project, please go to the release page of each community to download and decompression run.
- [Nacos: version 2.1.0](https://github.com/alibaba/nacos/releases)
- [Nacos: version 2.1.0](https://github.com/alibaba/nacos/releases)
- [Seata: version 1.5.1](https://github.com/seata/seata/releases)
- [Seata: version 1.5.1](https://github.com/seata/seata/releases)
- [RocketMQ: version 4.9.4](https://github.com/apache/rocketmq/releases)
- [RocketMQ: version 4.9.4](https://github.com/apache/rocketmq/releases)
- MySQL: version 5.7
- MySQL: version 5.7
### host configuration
### Hosts configuration
To ensure that the code can start properly, please configure the local host mapping first, add the following mapping to the configuration file.
To ensure that the code can start properly, please configure the local host mapping first, add the following mapping to the configuration file.
```sh
```shell
# for integrated-example
# for integrated-example
127.0.0.1 integrated-mysql
127.0.0.1 integrated-mysql
127.0.0.1 nacos-server
127.0.0.1 nacos-server
@ -42,7 +43,7 @@ Before you start the database configuration, please make sure the MySQL server i
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.
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.
Run the sql script `spring-cloud-alibaba-examples/integrated-example/config-init/sql/init.sql` to create the environment required for the business and the Seata-related tables in one click.
### Nacos Configuration
### Nacos Configuration
@ -52,7 +53,7 @@ At this point, the database services are configured and you need to configure th
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.
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
```shell
#Linux/Mac environment
#Linux/Mac environment
sh bin/startup.sh -m standalone
sh bin/startup.sh -m standalone
#If you are in Ubuntu and the above command gives you an error [[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
Before bulk importing the configuration, please modify 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 `spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml`.
After that, 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/config/scripts/nacos-config-quick.sh` to complete the one-click import of all microservice configurations.
```shell
# linux
sh nacos-config-quick.sh
# windows can use git bash to import the configuration, run the command as above
```
### Seata Configuration
### Seata Configuration
@ -77,7 +84,7 @@ Seata's db mode requires additional configuration of database information and mo
Go to the seata directory after the release and execute the following command.
Go to the seata directory after the release and execute the following command.
```sh
```shell
#Linux/Mac environment
#Linux/Mac environment
sh . /bin/seata-server.sh
sh . /bin/seata-server.sh
#Win environment
#Win environment
@ -92,7 +99,7 @@ Go to the unpacked rocketmq directory after the release and execute the followin
#### Start the NameServer
#### Start the NameServer
```sh
```shell
#Linux/Mac environment
#Linux/Mac environment
sh bin/mqnamesrv
sh bin/mqnamesrv
#Win environment
#Win environment
@ -101,7 +108,7 @@ sh bin/mqnamesrv
#### Start Broker
#### Start Broker
```sh
```shell
#Linux/Mac environment
#Linux/Mac environment
sh bin/mqbroker
sh bin/mqbroker
#Win environment
#Win environment
@ -112,10 +119,10 @@ sh bin/mqbroker
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.
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.
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.
- `integrated-frontend` module is front page for best practice examples.
- frontend is the simple front-end page for the best practice.
- `integral-gateway` module is the gateway for the entire best practice example.
### Distributed Transaction Capabilities
### Distributed Transaction Capabilities
@ -129,11 +136,11 @@ For the distributed transaction capability, we provide the scenario **where a us
Visit `http://integrated-frontend:8080/order` to experience the corresponding scenario.
Visit `http://integrated-frontend:8080/order` to experience the corresponding scenario.
By clicking the order button directly 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, application simulate the client sending a request to the gateway to create an order.
- The user's userId is admin
- The user's userId is admin
- The item number of the user's order is 1
- The item number of the user's order is 1
@ -143,7 +150,7 @@ By clicking the order button directly to submit the form, we simulate the client
In this demo example, the unit price of each item is 2 for demonstration purposes.
In this demo example, the unit price of each item is 2 for demonstration purposes.
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.
And in the previous preparation, **initialize business database table**application created a new user, the user's userId is 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).
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).
@ -159,14 +166,14 @@ You can see that the database still has 99 records in stock because of the rollb
#### Scenario Description
#### 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.
For service fusion limiting and peak and valley cutting in the context of high traffic, SCA community 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.
- 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.
- 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
#### Startup test
Start the `integrated_provider` and `integrated_consumer` modules separately.
Start the `integrated-praise-provider` and `integrated-praise-consumer` modules separately.
- Sentinel service meltdown degradation
- Sentinel service meltdown degradation
@ -184,7 +191,7 @@ Therefore, we can see that Sentinel performs a service fusion on the Gateway sid
Visit `http://integrated-frontend:8080/rocketmq` to experience the corresponding scenario.
Visit `http://integrated-frontend:8080/rocketmq` to experience the corresponding scenario.
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`
Since previously configured the consumption rate and interval of the `integrated-praise-consumer` consumer module in Nacos, simulate 1000 requests for likes at the click of a button, and the `integrated-praise-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.
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.
You can see that the number of likes in the database is being dynamically updated.
This project is a demo of Spring Cloud Alibaba containerized deployment best practices, and is an example project integrating Spring Cloud Alibaba components (Nacos, Sentinel, Seata, RocketMQ).
This project is a demo of Spring Cloud Alibaba (hereinafter referred to as SCA) containerized deployment best practices, and is an example project integrating SCA components (Nacos, Sentinel, Seata, RocketMQ).
The main components used and their usage features are as follows.
The main components used and their usage features are as follows.
@ -18,7 +18,7 @@ The main components used and their usage features are as follows.
## Application Scenario Description
## Application Scenario Description
In this demo, we provide two business scenarios.
In this demo, SCA community provide two business scenarios.
1) A scenario where a user places an order for goods and after placing the order.
1) A scenario where a user places an order for goods and after placing the order.
@ -34,7 +34,7 @@ In this demo, we provide two business scenarios.
1) In which the scenario where the user places an order for the goods mainly uses Seata to perform distributed transactions to represent the capabilities.
1) In which the scenario where the user places an order for the goods mainly uses Seata to perform distributed transactions to represent the capabilities.
2) The scenario where the user likes a product simulates a high traffic environment with Sentinel for flow limiting or RocketMQ for peak shaving. In this scenario, we provide two ways to deal with high traffic.
2) The scenario where the user likes a product simulates a high traffic environment with Sentinel for flow limiting or RocketMQ for peak shaving. In this scenario, SCA community provide two ways to deal with high traffic.
- Sentinel binds a specified gateway route on the gateway side for service fusion degradation.
- Sentinel binds a specified gateway route on the gateway side for service fusion degradation.
- RocketMQ performs peak-shaving, where producers send messages to RocketMQ and consumers pull and consume at configurable consumption rates, reducing the pressure of high traffic direct requests to the database and increasing the number of likes.
- RocketMQ performs peak-shaving, where producers send messages to RocketMQ and consumers pull and consume at configurable consumption rates, reducing the pressure of high traffic direct requests to the database and increasing the number of likes.
@ -78,8 +78,10 @@ By sending high volume like requests from the producer to the mq, the consumer m
## Release Notes
## Release Notes
This project provides a [local-deployment](local-deployment.md) and a [Kubernetes Helm-Chart version](kubernetes-deployment.md).
This project provides a [local-deployment](local-deployment.md), [docker-compose version](docker-compose-deployment.md) and a [Kubernetes Helm-Chart version](kubernetes-deployment.md).
- To learn how to configure the components and build the complete environment, we recommend learning the [local-deployment](local-deployment.md).
- To learn how to configure the components and build the complete environment, we recommend learning the [local-deployment](local-deployment.md).
- If you only want to run the sample code, avoid the tedious local environment construction process, and do not want to use the K8S cluster. You can try using [docker-compose version] (docker-compose-deployment.md).
- If you want to quickly experience the components on a K8S cluster and skip the process of deploying each component, please check out the [Kubernetes Helm-Chart version](kubernetes-deployment.md).
- If you want to quickly experience the components on a K8S cluster and skip the process of deploying each component, please check out the [Kubernetes Helm-Chart version](kubernetes-deployment.md).
进入`spring-cloud-alibaba-examples/integrated-example`目录下,在终端中执行以下命令`docker-compose -f ./docker-compose/docker-compose-service.yml up -d`来快速部署运行example所需服务。