From 7d9703870bd0783ed02d4143f7c5e5841d5846cd Mon Sep 17 00:00:00 2001 From: YuLuo <1481556636@qq.com> Date: Wed, 15 Mar 2023 13:48:40 +0800 Subject: [PATCH] update doc wrong and add docker support for in integrated-example (#3204) --- .../config/datasource-config.yaml | 2 +- .../config/integrated-account.yaml | 0 .../config/integrated-consumer.yaml | 0 .../config/integrated-gateway.yaml | 0 .../config/integrated-order.yaml | 0 .../config/integrated-provider.yaml | 0 .../config/integrated-storage.yaml | 0 .../config-init/rocketmq/broker.conf | 23 +++ .../scripts/nacos-config-quick.sh | 0 .../{ => config-init}/sql/init.sql | 0 .../integrated-example/docker-compose/.env | 8 + .../docker-compose/docker-compose-env.yml | 72 ++++++++ .../docker-compose/docker-compose-service.yml | 91 ++++++++++ .../docs/en/docker-compose-deployment.md | 157 +++++++++++++++++ .../docs/en/kubernetes-deployment.md | 24 +-- .../docs/en/local-deployment.md | 47 +++--- .../integrated-example/docs/en/readme.md | 10 +- .../docs/zh/docker-compose-deploy-zh.md | 159 ++++++++++++++++++ .../docs/zh/kubernetes-deployment-zh.md | 24 +-- .../docs/zh/local-deployment-zh.md | 51 +++--- .../integrated-example/docs/zh/readme-zh.md | 10 +- .../integrated-account/Dockerfile | 12 +- .../integrated-frontend/Dockerfile | 15 +- .../integrated-gateway/Dockerfile | 12 +- .../integrated-order/Dockerfile | 12 +- .../integrated-praise-consumer/Dockerfile | 12 +- .../integrated-praise-provider/Dockerfile | 12 +- .../integrated-storage/Dockerfile | 12 +- spring-cloud-alibaba-examples/pom.xml | 18 ++ 29 files changed, 686 insertions(+), 97 deletions(-) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/datasource-config.yaml (73%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/integrated-account.yaml (100%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/integrated-consumer.yaml (100%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/integrated-gateway.yaml (100%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/integrated-order.yaml (100%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/integrated-provider.yaml (100%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/config/integrated-storage.yaml (100%) create mode 100644 spring-cloud-alibaba-examples/integrated-example/config-init/rocketmq/broker.conf rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/scripts/nacos-config-quick.sh (100%) rename spring-cloud-alibaba-examples/integrated-example/{ => config-init}/sql/init.sql (100%) create mode 100644 spring-cloud-alibaba-examples/integrated-example/docker-compose/.env create mode 100644 spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-env.yml create mode 100644 spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-service.yml create mode 100644 spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md create mode 100644 spring-cloud-alibaba-examples/integrated-example/docs/zh/docker-compose-deploy-zh.md diff --git a/spring-cloud-alibaba-examples/integrated-example/config/datasource-config.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml similarity index 73% rename from spring-cloud-alibaba-examples/integrated-example/config/datasource-config.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml index e3cc76339..fb6ff397b 100644 --- a/spring-cloud-alibaba-examples/integrated-example/config/datasource-config.yaml +++ b/spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml @@ -2,7 +2,7 @@ spring: datasource: driver-class-name: com.mysql.jdbc.Driver username: 'root' - password: '123456' + password: 'root' main: allow-bean-definition-overriding: true mybatis: diff --git a/spring-cloud-alibaba-examples/integrated-example/config/integrated-account.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-account.yaml similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/config/integrated-account.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-account.yaml diff --git a/spring-cloud-alibaba-examples/integrated-example/config/integrated-consumer.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-consumer.yaml similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/config/integrated-consumer.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-consumer.yaml diff --git a/spring-cloud-alibaba-examples/integrated-example/config/integrated-gateway.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-gateway.yaml similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/config/integrated-gateway.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-gateway.yaml diff --git a/spring-cloud-alibaba-examples/integrated-example/config/integrated-order.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-order.yaml similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/config/integrated-order.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-order.yaml diff --git a/spring-cloud-alibaba-examples/integrated-example/config/integrated-provider.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-provider.yaml similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/config/integrated-provider.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-provider.yaml diff --git a/spring-cloud-alibaba-examples/integrated-example/config/integrated-storage.yaml b/spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-storage.yaml similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/config/integrated-storage.yaml rename to spring-cloud-alibaba-examples/integrated-example/config-init/config/integrated-storage.yaml diff --git a/spring-cloud-alibaba-examples/integrated-example/config-init/rocketmq/broker.conf b/spring-cloud-alibaba-examples/integrated-example/config-init/rocketmq/broker.conf new file mode 100644 index 000000000..61e6e8b3e --- /dev/null +++ b/spring-cloud-alibaba-examples/integrated-example/config-init/rocketmq/broker.conf @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +brokerIP1=172.20.0.4 +brokerClusterName = DefaultCluster +brokerName = broker-a +brokerId = 0 +deleteWhen = 04 +fileReservedTime = 48 +brokerRole = ASYNC_MASTER +flushDiskType = ASYNC_FLUSH diff --git a/spring-cloud-alibaba-examples/integrated-example/scripts/nacos-config-quick.sh b/spring-cloud-alibaba-examples/integrated-example/config-init/scripts/nacos-config-quick.sh similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/scripts/nacos-config-quick.sh rename to spring-cloud-alibaba-examples/integrated-example/config-init/scripts/nacos-config-quick.sh diff --git a/spring-cloud-alibaba-examples/integrated-example/sql/init.sql b/spring-cloud-alibaba-examples/integrated-example/config-init/sql/init.sql similarity index 100% rename from spring-cloud-alibaba-examples/integrated-example/sql/init.sql rename to spring-cloud-alibaba-examples/integrated-example/config-init/sql/init.sql diff --git a/spring-cloud-alibaba-examples/integrated-example/docker-compose/.env b/spring-cloud-alibaba-examples/integrated-example/docker-compose/.env new file mode 100644 index 000000000..4062895a6 --- /dev/null +++ b/spring-cloud-alibaba-examples/integrated-example/docker-compose/.env @@ -0,0 +1,8 @@ +# port +GATEWAY_PORT=30010 +ACCOUNT_PORT=8012 +FRONTEND_PORT=8080 +ORDER_PORT=8013 +STORAGE_PORT=8011 +PRAISE_PROVIDER_PORT=8015 +PRAISE_CONSUMER_PORT=8014 diff --git a/spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-env.yml b/spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-env.yml new file mode 100644 index 000000000..494e28e9d --- /dev/null +++ b/spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-env.yml @@ -0,0 +1,72 @@ +version: "3" +services: + + # nacos + nacos: + image: nacos/nacos-server:v2.1.0 + hostname: nacos-server + restart: always + container_name: integrated-example-nacos + environment: + - PREFER_HOST_MODE=hostname + - MODE=standalone + ports: + - "8848:8848" + + # mysql + mysql: + container_name: integrated-example-mysql + hostname: integrated-mysql + restart: always + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: integrated_storage + ports: + - "3306:3306" + volumes: + - ../config-init/sql/init.sql:/docker-entrypoint-initdb.d/init.sql + command: + [ + --character-set-server=utf8mb4, + --collation-server=utf8mb4_unicode_ci + ] + + # rocketMQ + rmqnamesrv: + image: apache/rocketmq:4.9.4 + hostname: rocketmq + restart: always + container_name: integrated-example-rmqnamesrv + ports: + - "9876:9876" + command: sh mqnamesrv + + rmqbroker: + image: apache/rocketmq:4.9.4 + restart: always + container_name: integrated-example-rmqbroker + ports: + - "10909:10909" + - "10911:10911" + volumes: + - ../config-init/rocketmq/broker.conf:/opt/rocketmq-4.9.4/conf/broker.conf + environment: + NAMESRV_ADDR: "rmqnamesrv:9876" + JAVA_OPTS: " -Duser.home=/opt" + JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m" + command: sh mqbroker -c /opt/rocketmq-4.9.4/conf/broker.conf + depends_on: + - rmqnamesrv + + # seata + seata-server: + image: seataio/seata-server:1.5.1 + hostname: seata-server + restart: always + container_name: integrated-example-seata-server + ports: + - "8091:8091" + environment: + - SEATA_PORT=8091 + - STORE_MODE=file diff --git a/spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-service.yml b/spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-service.yml new file mode 100644 index 000000000..51a956343 --- /dev/null +++ b/spring-cloud-alibaba-examples/integrated-example/docker-compose/docker-compose-service.yml @@ -0,0 +1,91 @@ +version: "3" +services: + + # integrated example module + integrated-frontend: + image: integrated-frontend + hostname: integrated-frontend + build: + dockerfile: ./integrated-frontend/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-frontend + ports: + - ${FRONTEND_PORT}:${FRONTEND_PORT} + depends_on: + - integrated-gateway + - integrated-account + - integrated-order + - integrated-storage + - integrated-praise-consumer + - integrated-praise-provider + + integrated-gateway: + image: integrated-gateway + hostname: gateway-service + build: + dockerfile: ./integrated-gateway/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-gateway + ports: + - ${GATEWAY_PORT}:${GATEWAY_PORT} + + integrated-account: + image: integrated-account + build: + dockerfile: ./integrated-account/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-account + ports: + - ${ACCOUNT_PORT}:${ACCOUNT_PORT} + + integrated-order: + image: integrated-order + build: + dockerfile: ./integrated-order/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-order + ports: + - ${ORDER_PORT}:${ORDER_PORT} + + integrated-storage: + image: integrated-storage + build: + dockerfile: ./integrated-storage/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-storage + ports: + - ${STORAGE_PORT}:${STORAGE_PORT} + + integrated-praise-provider: + image: integrated-praise-provider + build: + dockerfile: ./integrated-praise-provider/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-praise-provider + ports: + - ${PRAISE_PROVIDER_PORT}:${PRAISE_PROVIDER_PORT} + + integrated-praise-consumer: + image: integrated-praise-consumer + build: + dockerfile: ./integrated-praise-consumer/Dockerfile + context: ../ + env_file: + - .env + container_name: integrated-praise-consumer + ports: + - ${PRAISE_CONSUMER_PORT}:${PRAISE_CONSUMER_PORT} + depends_on: + - integrated-praise-provider diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md b/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md new file mode 100644 index 000000000..c51cc6896 --- /dev/null +++ b/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md @@ -0,0 +1,157 @@ +# Spring Cloud Alibaba Containerized Deployment Best Practices | Docker-Compose Edition + +## Preparation + +If you have not installed Docker or Docker-Compose, please follow the official documentation to build the environment + +> Note: When using Docker-Compose to experience the demo, please make sure that the local machine memory resource is >= 24G! + +- Docker:https://docs.docker.com/desktop/install/linux-install/ +- Docker-Compose:https://docs.docker.com/compose/install/ + +### 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. + +```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 +- Deduct the account balance +- Generate order information to return a response + +##### Start test + +Start `integrated-storage`,`integrated-account`,`integrated-order` microservices respectively. + +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. + +- The user's userId is admin +- 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-20221016155416524.png) + +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). + +![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155429801.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-20221016155436112.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 + +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. + +![](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. + +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 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. + +![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016173604059.png) + +## Other + +This example **is just a selection of typical features for each component to serve the application scenario**. + +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.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) diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/en/kubernetes-deployment.md b/spring-cloud-alibaba-examples/integrated-example/docs/en/kubernetes-deployment.md index 528206864..968cf1b3f 100644 --- a/spring-cloud-alibaba-examples/integrated-example/docs/en/kubernetes-deployment.md +++ b/spring-cloud-alibaba-examples/integrated-example/docs/en/kubernetes-deployment.md @@ -2,18 +2,18 @@ ## Preparation -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.) - 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. - [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 +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. +```shell # Please adjust with the public ip of your K8S node 120.24.xxx.xxx integrated-frontend 120.24.xxx.xxx gateway-service @@ -30,7 +30,7 @@ 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. +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. @@ -43,7 +43,7 @@ helm uninstall integrated-example #### 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. +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 - 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. -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 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. -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). +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, 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). ![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143057730.png) @@ -78,7 +78,7 @@ You can see that the database still has 99 records in stock because of the rollb #### 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. - 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 ![](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` +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. 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**. -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. - Nacos examples - [Nacos config example](../../../nacos-example/nacos-config-example/readme.md) diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/en/local-deployment.md b/spring-cloud-alibaba-examples/integrated-example/docs/en/local-deployment.md index 44e69deae..34e2fed67 100644 --- a/spring-cloud-alibaba-examples/integrated-example/docs/en/local-deployment.md +++ b/spring-cloud-alibaba-examples/integrated-example/docs/en/local-deployment.md @@ -4,7 +4,8 @@ ### 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 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 - Seata server @@ -13,18 +14,18 @@ Before running the local example, you need to ensure that the following base env ### 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) - [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 +### 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. -```sh +```shell # for integrated-example 127.0.0.1 integrated-mysql 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. -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 @@ -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. -```sh +```shell #Linux/Mac environment 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 @@ -63,9 +64,15 @@ bash bin/startup.sh -m standalone #### Adding configuration files -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 @@ -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. -```sh +```shell #Linux/Mac environment sh . /bin/seata-server.sh #Win environment @@ -92,7 +99,7 @@ Go to the unpacked rocketmq directory after the release and execute the followin #### Start the NameServer -```sh +```shell #Linux/Mac environment sh bin/mqnamesrv #Win environment @@ -101,7 +108,7 @@ sh bin/mqnamesrv #### Start Broker -```sh +```shell #Linux/Mac environment sh bin/mqbroker #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. -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. -- frontend is the simple front-end page for the best practice. +- `integrated-frontend` module is front page for best practice examples. +- `integral-gateway` module is the gateway for the entire best practice example. ### Distributed Transaction Capabilities @@ -129,11 +136,11 @@ For the distributed transaction capability, we provide the scenario **where a us ##### Start test -Start `integrated_storage`,`integrated_account`,`integrated_order` microservices respectively. +Start `integrated-storage`,`integrated-account`,`integrated-order` microservices respectively. 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 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. -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). @@ -159,14 +166,14 @@ You can see that the database still has 99 records in stock because of the rollb #### 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. - 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_provider` and `integrated_consumer` modules separately. +Start the `integrated-praise-provider` and `integrated-praise-consumer` modules separately. - 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. -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. You can see that the number of likes in the database is being dynamically updated. diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/en/readme.md b/spring-cloud-alibaba-examples/integrated-example/docs/en/readme.md index cb36466d9..06f4a9874 100644 --- a/spring-cloud-alibaba-examples/integrated-example/docs/en/readme.md +++ b/spring-cloud-alibaba-examples/integrated-example/docs/en/readme.md @@ -2,7 +2,7 @@ ## Project Description -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. @@ -18,7 +18,7 @@ The main components used and their usage features are as follows. ## 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. @@ -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. -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. - 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 -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). +- 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). \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/zh/docker-compose-deploy-zh.md b/spring-cloud-alibaba-examples/integrated-example/docs/zh/docker-compose-deploy-zh.md new file mode 100644 index 000000000..0710d2e5b --- /dev/null +++ b/spring-cloud-alibaba-examples/integrated-example/docs/zh/docker-compose-deploy-zh.md @@ -0,0 +1,159 @@ +# Spring Cloud Alibaba容器化部署最佳实践 | Docker-Compose 版本 + +## 准备工作 + +> Note: 使用Docker-Compose方式体验Demo时,请确保本地机器内存资源 >= 24G! + +如果您还没有安装Docker和Docker-Compose,请按照官方文档来构建运行环境: + +- Docker:https://docs.docker.com/desktop/install/linux-install/ +- Docker-Compose:https://docs.docker.com/compose/install/ + +### Hosts 配置 + +为确保代码能够正常启动,请先配置本地主机映射,将以下映射添加到配置文件中。 + +```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 +``` + +### 准备jar包 + +进入`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所需组件。 + +### 添加配置 + +docker-compose-env.yml文件运行成功之后,添加Nacos配置: + +1. 进入`spring-cloud-alibaba-examples/integrated-example`目录下; +2. 在终端中执行`config-init/scripts/nacos-config-quick.sh`脚本文件。 + +完成所有微服务配置的一键导入。 + +> 注意: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 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`观察容器的启动过程! + +## 体验Demo + +准备工作完成后可以运行 demo 示例,主要根据不同的使用场景,可以分别体验用户下单(分布式事务能力)以及模拟高流量点赞(熔断限流以及削峰填谷的能力)。 + +首先需要分别启动`integrated-frontend`以及`integrated-gateway`微服务应用。 + +- `integrated-gateway` 模块是整个最佳实践示例的网关。 +- `integrated-frontend` 为最佳实践示例的简易前端页面。 + +### 分布式事务能力 + +#### 场景说明 + +针对分布式事务能力,SCA社区提供了**用户下单购买货物的场景**,下单后: + +- 先请求库存模块,扣减库存 +- 扣减账户余额 +- 生成订单信息返回响应 + +##### 启动测试 + +分别启动`integrated-storage`,`integrated-account`,`integrated-order`三个微服务应用。 + +访问`http://integrated-frontend:8080/order` 来体验对应场景。 + +直接点击下单按钮提交表单,应用模拟客户端向网关发送了一个创建订单的请求。 + +- 用户的 userId 为 admin +- 用户下单的商品编号为1号 +- 此次订单购买的商品个数为1个 + +![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155416524.png) + +在本 demo 示例中,为了便于演示,每件商品的单价都为2。 + +而在前面的准备工作中,**初始化业务数据库表**的时候应用新建了一个用户,用户userId 为 admin,余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。 + +因此通过上述的操作,应用会创建一个订单,扣减对应商品编号为 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 捕获,执行分布式事务二阶段提交,回滚事务。 + +![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155436112.png) + +可以看到数据库中库存的记录因为回滚之后仍然为 99 件。 + +### 熔断限流,削峰填谷能力 + +#### 场景说明 + +针对大流量背景下的服务熔断限流,削峰填谷,SCA社区提供了**用户为商品进行点赞的场景**。在此场景下,SCA社区提供了两种应对大流量的处理方式。 + +- Sentinel 在网关侧绑定指定网关路由进行服务的熔断降级。 +- RocketMQ 进行流量削峰填谷,在大流量请求下,生产者向 RocketMQ 发送消息,而消费者则通过可配置的消费速率进行拉取消费,减少大流量直接请求数据库增加点赞请求的压力。 + +#### 启动测试 + +分别启动`integrated-praise-provider`以及`integrated-praise-consumer`模块。 + +- Sentinel 服务熔断降级 + +访问`http://integrated-frontend:8080/sentinel` 体验对应场景。 + +![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016155501290.png) + +网关路由点赞服务的限流规则为 5,而在前端通过异步处理模拟了 10 次并发请求。 + +因此可以看到 Sentinel 在 Gateway 侧针对多出的流量进行了服务熔断返回 fallback 给客户端,同时数据库的点赞数进行了更新(+5)。 + +![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20220914155755103.png) + +- RocketMQ 进行流量削峰填谷 + +访问`http://integrated-frontend:8080/rocketmq` 体验对应场景。 + +由于之前在 Nacos 中配置了`integrated-praise-consumer`消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider` +会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。 + +可以看到数据库中点赞的个数正在动态更新。 + +![image-20221016173604059](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016173604059.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) + diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md b/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md index b18d652b9..57d21ee18 100644 --- a/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md +++ b/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md @@ -2,17 +2,17 @@ ## 准备工作 -此版本为 Spring Cloud Alibaba 最佳实践 Kubernetes 部署版本,其中需要您准备如下的环境。 +此版本为 Spring Cloud Alibaba (后文简称为SCA)最佳实践 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 映射。 +在这里通过 NodePort 的方式来向外界暴露 Kubernetes 中 Pod 的服务,在启动测试前还需配置好 Kubernetes 集群节点的 ip 映射。 ```sh # 实际情况请结合您的 K8S 节点的公网 ip 进行调整 @@ -31,9 +31,9 @@ helm package helm-chart helm install integrated-example integrated-example-1.0.0.tgz ``` -通过上述命令我们根据项目提供的 Helm Chart 文档通过 Helm 一键完成了最佳实践项目的部署。 +通过运行上述命令,根据SCA社区提供的 Helm Chart 文档通过 Helm 快速完成最佳实践示例的部署。 -可以通过 Kubernetes 提供的 `kubectl` 命令查看各容器资源部署的情况,耐心等待**所有容器完成启动后**即可到对应页面体验各个组件使用场景及能力。 +可以通过 Kubernetes 提供的 `kubectl` 命令查看各容器资源部署的情况,耐心等待**所有容器完成启动后**即可到对应页面体验各个组件的使用场景及能力。 如果您想停止体验,输入如下命令。 ```shell @@ -44,7 +44,7 @@ helm uninstall integrated-example #### 场景说明 -针对分布式事务能力,我们提供了**用户下单购买货物的场景**,下单后: +针对分布式事务能力,SCA社区提供了**用户下单购买货物的场景**,下单后: - 先请求库存模块,扣减库存 - 扣减账户余额 @@ -54,7 +54,7 @@ helm uninstall integrated-example 访问`http://integrated-frontend:30080/order` 来体验对应场景。 -直接点击下单按钮提交表单,我们模拟客户端向网关发送了一个创建订单的请求。 +直接点击下单按钮提交表单,模拟客户端向网关发送了一个创建订单的请求。 - 用户的 userId 为 admin - 用户下单的商品编号为1号 @@ -64,9 +64,9 @@ helm uninstall integrated-example 在本 demo 示例中,为了便于演示,每件商品的单价都为2。 -而在 `integrated-mysql` 容器的初始化时,**初始化业务数据库表**的时候新建了一个用户 userId = admin,余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。 +而在 `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) @@ -80,7 +80,7 @@ helm uninstall integrated-example #### 场景说明 -针对大流量背景下的服务熔断限流,削峰填谷,我们提供了**用户为商品进行点赞的场景**。在此场景下,我们提供了两种应对大流量的处理方式。 +针对大流量背景下的服务熔断限流,削峰填谷,SCA社区提供了**用户为商品进行点赞的场景**。在此场景下,SCA社区提供了两种应对大流量的处理方式。 - Sentinel 在网关侧绑定指定网关路由进行服务的熔断降级。 - RocketMQ 进行流量削峰填谷,在大流量请求下,生产者向 RocketMQ 发送消息,而消费者则通过可配置的消费速率进行拉取消费,减少大流量直接请求数据库增加点赞请求的压力。 @@ -105,7 +105,7 @@ helm uninstall integrated-example ![](https://my-img-1.oss-cn-hangzhou.aliyuncs.com/image-20221016143342664.png) -由于我们之前在 Nacos 中配置了`integrated-consumer`消费者模块的消费速率以及间隔,在点击按钮时我们模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated_provider` +由于之前在 Nacos 中配置了`integrated-praise-consumer`消费者模块的消费速率以及间隔,在点击按钮时应用将会模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider` 会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。 可以看到数据库中点赞的个数正在动态更新。 @@ -116,7 +116,7 @@ helm uninstall integrated-example 本示例**仅是针对各个组件选取出了较为典型的功能特性来服务应用场景**。 -当然各个组件的功能特性不仅仅只包含最佳实践中演示的这些,如果您感兴趣或是想要深入了解,欢迎学习各个组件的独立 example 相关文档。 +当然各个组件的功能特性不仅仅只包含最佳实践中演示的这些,如果您对SCA感兴趣或是想要深入了解SCA项目,欢迎阅览各个组件的独立 example 相关文档。 - Nacos examples - [Nacos config example](../../../nacos-example/nacos-config-example/readme-zh.md) diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/zh/local-deployment-zh.md b/spring-cloud-alibaba-examples/integrated-example/docs/zh/local-deployment-zh.md index d8e8d9ac3..9f3d0dc6a 100644 --- a/spring-cloud-alibaba-examples/integrated-example/docs/zh/local-deployment-zh.md +++ b/spring-cloud-alibaba-examples/integrated-example/docs/zh/local-deployment-zh.md @@ -5,6 +5,7 @@ ### 环境声明 在运行本地示例之前,需要保证本机具备以下的基础环境,如果您的本地没有当前的环境,下面会一步步进行搭建,演示搭建过程。 +当然您也可以通过 Spring Cloud Alibaba (下文简称为SCA)社区提供的docker-compose文件快速启动相应组件。 - Nacos 服务端 - Seata 服务端 @@ -13,17 +14,17 @@ ### 组件服务版本 -本项目的各个组件版本请移步至各个社区的 release 页面进行下载并解压。 +本项目的各个组件版本请移步至各个社区的 release 页面进行下载并解压运行。 - [Nacos: 2.1.0 版本](https://github.com/alibaba/nacos/releases) - [Seata: 1.5.1 版本](https://github.com/seata/seata/releases) - [RocketMQ: 4.9.4 版本](https://github.com/apache/rocketmq/releases) - MySQL: 5.7 版本 -### host配置 +### Hosts配置 为了保证代码可以正常启动,请先配置好本机的 host 映射,在配置文件中新增如下的映射。 -```sh +```shell # for integrated-example 127.0.0.1 integrated-mysql 127.0.0.1 nacos-server @@ -41,7 +42,7 @@ 针对第一个场景,订单、账户、库存微服务都需要各自的数据库,而第二个场景模拟点赞也需要存储点赞信息的数据库。 -运行 `spring-cloud-alibaba-examples/integrated-example/sql/init.sql` 的 sql 脚本一键创建业务所需的环境以及 Seata 相关的表。 +运行 `spring-cloud-alibaba-examples/integrated-example/config-init/sql/init.sql` 的 sql 脚本一键创建业务所需的环境以及 Seata 相关的表。 ### Nacos配置 @@ -51,7 +52,7 @@ 为了便于 example 的演示,这里采用 Nacos 的`standalone`模式启动,进入到 Nacos 解压后的目录下,执行如下命令。 -```sh +```shell #Linux/Mac环境 sh bin/startup.sh -m standalone #如果您是Ubuntu环境,执行上述命令启动报错提示[[符号找不到,可以执行如下的命令 @@ -62,9 +63,15 @@ bash bin/startup.sh -m standalone #### 新增配置文件 -在批量导入配置之前,请先修改`integrated-example/config/datasource-config.yaml` 中的数据源配置(用户名和密码)。 +在批量导入配置之前,请先修改`spring-cloud-alibaba-examples/integrated-example/config-init/config/datasource-config.yaml` 中的数据源配置**(用户名和密码)**。 -之后运行`spring-cloud-alibaba-examples/integrated-example/scripts/nacos-config-quick.sh` 来完成所有微服务配置的一键导入。 +之后运行`spring-cloud-alibaba-examples/integrated-example/config-init/scripts/nacos-config-quick.sh` 来完成所有微服务配置的一键导入。 + +```shell +# linux +sh nacos-config-quick.sh +# windows 可以使用git bash来完成配置的导入 执行命令同上 +``` ### Seata 配置 @@ -76,7 +83,7 @@ Seata 的 db 模式需要额外配置数据库信息以及修改 Seata 服务端 进入到 release 解压后的 seata 目录中,执行如下命令。 -```sh +```shell #Linux/Mac环境 sh ./bin/seata-server.sh #Win环境 @@ -91,7 +98,7 @@ Seata 服务启动后可以启动 RocketMQ 的 NameServer 以及 Broker 服务 #### 启动 NameServer -```sh +```shell #Linux/Mac环境 sh bin/mqnamesrv #Win环境 @@ -100,27 +107,27 @@ sh bin/mqnamesrv #### 启动 Broker -```sh +```shell #Linux/Mac环境 sh bin/mqbroker #Win环境 -.\bin\mqbroker.cmd +.\bin\mqbroker.cmd -n localhost:9876 ``` ## 运行 Demo 示例 准备工作完成后可以运行 demo 示例,主要根据不同的使用场景,可以分别体验用户下单(分布式事务能力)以及模拟高流量点赞(熔断限流以及削峰填谷的能力)。 -首先需要分别启动`integrated_frontend`以及`integrated_gateway`的工程。 +首先需要分别启动`integrated-frontend`以及`integrated-gateway`微服务应用。 -- gateway 模块是整个最佳实践实例的网关。 -- frontend 为最佳实践的简易前端页面。 +- `integrated-gateway` 模块是整个最佳实践示例的网关。 +- `integrated-frontend` 为最佳实践示例的简易前端页面。 ### 分布式事务能力 #### 场景说明 -针对分布式事务能力,我们提供了**用户下单购买货物的场景**,下单后: +针对分布式事务能力,SCA社区提供了**用户下单购买货物的场景**,下单后: - 先请求库存模块,扣减库存 - 扣减账户余额 @@ -128,11 +135,11 @@ sh bin/mqbroker ##### 启动测试 -分别启动`integrated_storage`,`integrated_account`,`integrated_order`三个微服务。 +分别启动`integrated-storage`,`integrated-account`,`integrated-order`三个微服务应用。 访问`http://integrated-frontend:8080/order` 来体验对应场景。 -直接点击下单按钮提交表单,我们模拟客户端向网关发送了一个创建订单的请求。 +直接点击下单按钮提交表单,应用模拟客户端向网关发送了一个创建订单的请求。 - 用户的 userId 为 admin - 用户下单的商品编号为1号 @@ -142,9 +149,9 @@ sh bin/mqbroker 在本 demo 示例中,为了便于演示,每件商品的单价都为2。 -而在前面的准备工作中,**初始化业务数据库表**的时候我们新建了一个用户 userId = admin,余额为 3 元;同时新建了一个编号为 1 号的商品,库存为 100 件。 +而在前面的准备工作中,**初始化业务数据库表**的时候应用新建了一个用户,用户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) @@ -158,14 +165,14 @@ sh bin/mqbroker #### 场景说明 -针对大流量背景下的服务熔断限流,削峰填谷,我们提供了**用户为商品进行点赞的场景**。在此场景下,我们提供了两种应对大流量的处理方式。 +针对大流量背景下的服务熔断限流,削峰填谷,SCA社区提供了**用户为商品进行点赞的场景**。在此场景下,SCA社区提供了两种应对大流量的处理方式。 - Sentinel 在网关侧绑定指定网关路由进行服务的熔断降级。 - RocketMQ 进行流量削峰填谷,在大流量请求下,生产者向 RocketMQ 发送消息,而消费者则通过可配置的消费速率进行拉取消费,减少大流量直接请求数据库增加点赞请求的压力。 #### 启动测试 -分别启动`integrated_provider`以及`integrated_consumer`模块。 +分别启动`integrated-praise-provider`以及`integrated-praise-consumer`模块。 - Sentinel 服务熔断降级 @@ -183,7 +190,7 @@ sh bin/mqbroker 访问`http://integrated-frontend:8080/rocketmq` 体验对应场景。 -由于我们之前在 Nacos 中配置了`integrated-consumer`消费者模块的消费速率以及间隔,在点击按钮时我们模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated_provider` +由于之前在 Nacos 中配置了`integrated-praise-consumer`消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider` 会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。 可以看到数据库中点赞的个数正在动态更新。 diff --git a/spring-cloud-alibaba-examples/integrated-example/docs/zh/readme-zh.md b/spring-cloud-alibaba-examples/integrated-example/docs/zh/readme-zh.md index f475c7639..a86c02b57 100644 --- a/spring-cloud-alibaba-examples/integrated-example/docs/zh/readme-zh.md +++ b/spring-cloud-alibaba-examples/integrated-example/docs/zh/readme-zh.md @@ -2,7 +2,7 @@ ## 项目说明 -本项目为 Spring Cloud Alibaba 容器化部署最佳实践的 Demo 演示项目,是整合了 Spring Cloud Alibaba 相关组件( Nacos, Sentinel, Seata, RocketMQ)的 Example 示例项目。 +本项目为 Spring Cloud Alibaba (后文简称为SCA)容器化部署最佳实践的 Demo 演示项目,是整合了 SCA 相关组件( Nacos, Sentinel, Seata, RocketMQ)的 Example 示例项目。 主要使用的组件及及其使用特性如下: @@ -18,7 +18,7 @@ ## 应用场景说明 -在本 demo 示例中,我们提供了两种业务场景。 +在本 demo 示例中,SCA社区提供了两种业务场景。 1)用户下单购买货物的场景,下单后: @@ -34,7 +34,7 @@ 1)其中,用户下单购买货物的场景主要使用 Seata 来进行分布式事务的能力体现。 -2)用户为商品进行点赞的场景,模拟大流量环境下通过 Sentinel 进行限流或是 RocketMQ 进行削峰填谷。在此场景下,我们提供了两种应对大流量的处理方式: +2)用户为商品进行点赞的场景,模拟大流量环境下通过 Sentinel 进行限流或是 RocketMQ 进行削峰填谷。在此场景下,SCA社区提供了两种应对大流量的处理方式: - Sentinel 在网关侧绑定指定网关路由进行服务的熔断降级。 - RocketMQ 进行流量削峰填谷,在大流量请求下,生产者向 RocketMQ 发送消息,而消费者则通过可配置的消费速率进行拉取消费,减少大流量直接请求数据库增加点赞请求的压力。 @@ -78,8 +78,10 @@ Spring Cloud GateWay 整合 Nacos,实现动态路由配置。 ## 版本说明 -本项目提供了[本地部署运行版本](local-deployment-zh.md)以及[Kubernetes Helm-Chart 版本](kubernetes-deployment-zh.md)。 +本项目提供了[本地部署运行版本](local-deployment-zh.md)、[docker-compose版本](docker-compose-deployment-zh.md)以及[Kubernetes Helm-Chart 版本](kubernetes-deployment-zh.md)。 - 如果想要了解具体如何配置各项组件以及完整环境搭建,推荐学习[本地部署运行版本](local-deployment-zh.md)。 +- 如果只想运行示例代码,避免繁琐的本地环境搭建过程,又不想使用k8s集群。您可以尝试使用[docker-compose版本](docker-compose-deployment-zh.md)。 + - 如果想要在K8S集群上快速体验组件效果,跳过各个组件环境部署等过程,请查看[Kubernetes Helm-Chart 版本](kubernetes-deployment-zh.md)。 \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-account/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-account/Dockerfile index d1dc5fa4f..762e9b570 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-account/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-account/Dockerfile @@ -1,5 +1,11 @@ -FROM openjdk:8 -ADD /target/integrated-account-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-account/target/integrated-account-*.jar /app.jar + +RUN sh -c 'touch /app.jar' EXPOSE 8012 + ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-frontend/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-frontend/Dockerfile index 04cfb39bb..1bf3880b7 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-frontend/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-frontend/Dockerfile @@ -1,5 +1,12 @@ -FROM openjdk:8 -ADD /target/integrated-frontend-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-frontend/target/integrated-frontend-*.jar /app.jar + +RUN sh -c 'touch /app.jar' + EXPOSE 8080 -ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file + +ENTRYPOINT ["java", "-jar", "/app.jar"] diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-gateway/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-gateway/Dockerfile index 15a434d93..8fb93a28d 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-gateway/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-gateway/Dockerfile @@ -1,5 +1,11 @@ -FROM openjdk:8 -ADD /target/integrated-gateway-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-gateway/target/integrated-gateway-*.jar /app.jar + +RUN sh -c 'touch /app.jar' EXPOSE 30010 + ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-order/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-order/Dockerfile index 71d15a2d0..23cf648f9 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-order/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-order/Dockerfile @@ -1,5 +1,11 @@ -FROM openjdk:8 -ADD /target/integrated-order-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-order/target/integrated-order-*.jar /app.jar + +RUN sh -c 'touch /app.jar' EXPOSE 8013 + ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-praise-consumer/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-praise-consumer/Dockerfile index 3af24fa78..ac40e8e05 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-praise-consumer/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-praise-consumer/Dockerfile @@ -1,5 +1,11 @@ -FROM openjdk:8 -ADD /target/integrated-praise-consumer-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-praise-consumer/target/integrated-praise-consumer-*.jar /app.jar + +RUN sh -c 'touch /app.jar' EXPOSE 8014 + ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-praise-provider/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-praise-provider/Dockerfile index 752d35a3b..0f9f746ee 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-praise-provider/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-praise-provider/Dockerfile @@ -1,5 +1,11 @@ -FROM openjdk:8 -ADD /target/integrated-praise-provider-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-praise-provider/target/integrated-praise-provider-*.jar /app.jar + +RUN sh -c 'touch /app.jar' EXPOSE 8015 + ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/integrated-example/integrated-storage/Dockerfile b/spring-cloud-alibaba-examples/integrated-example/integrated-storage/Dockerfile index 7fcb50712..db3348737 100644 --- a/spring-cloud-alibaba-examples/integrated-example/integrated-storage/Dockerfile +++ b/spring-cloud-alibaba-examples/integrated-example/integrated-storage/Dockerfile @@ -1,5 +1,11 @@ -FROM openjdk:8 -ADD /target/integrated-storage-2.2.9-SNAPSHOT.jar /app.jar -RUN bash -c 'touch /app.jar' +FROM openjdk:8-jdk-alpine as builder + +LABEL author="yuluo" \ + email="yuluo829@aliyun.com" + +ADD ./integrated-storage/target/integrated-storage-*.jar /app.jar + +RUN sh -c 'touch /app.jar' EXPOSE 8011 + ENTRYPOINT ["java", "-jar","/app.jar"] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/pom.xml b/spring-cloud-alibaba-examples/pom.xml index ca6b3a007..a7b5aecb6 100644 --- a/spring-cloud-alibaba-examples/pom.xml +++ b/spring-cloud-alibaba-examples/pom.xml @@ -78,6 +78,24 @@ true + + + + org.apache.maven.plugins + maven-javadoc-plugin + + true + + + + + + org.apache.maven.plugins + maven-source-plugin + + true + +