Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
driver-class-name: com.mysql.cj.jdbc.Driver
username: 'root'
password: 'root'
main:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:
group: praise-consumer-group-PRAISE-TOPIC-01
rocketmq:
binder:
name-server: rocketmq:9876
name-server: rocketmq-server:9876
bindings:
consumer-in-0:
consumer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring:
content-type: application/json
rocketmq:
binder:
name-server: rocketmq:9876
name-server: rocketmq-server:9876
bindings:
praise-output:
producer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

brokerIP1=172.20.0.4
brokerIP1 = rocketmq-server
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#!/bin/sh
echo "Nacos auto config started"
datasourceConfig=$(cat ../config/datasource-config.yaml)
storageConfig=$(cat ../config/integrated-storage.yaml)
accountConfig=$(cat ../config/integrated-account.yaml)
orderConfig=$(cat ../config/integrated-order.yaml)
gatewayConfig=$(cat ../config/integrated-gateway.yaml)
providerConfig=$(cat ../config/integrated-provider.yaml)
consumerConfig=$(cat ../config/integrated-consumer.yaml)

config_dir="./config-init/config"
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"

# find all yaml config file then push to nacos
for config_file in $(find "${config_dir}" -type f -name "*.yaml"); do
# use filename as dataId
dataId=$(basename "$config_file")

# read file content
file_content=$(cat "$config_file")
echo "\npublish config ${config_file}"

# publish config to nacos
curl -X POST "nacos-server:8848/nacos/v1/cs/configs" \
-d "type=yaml" \
--data-urlencode "dataId=${dataId}" \
--data-urlencode "group=${groupId}" \
--data-urlencode "content=${file_content}"
done

echo "\npublish Nacos config finished"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# port
GATEWAY_PORT=30010
ACCOUNT_PORT=8012
FRONTEND_PORT=8080
FRONTEND_PORT=8010
ORDER_PORT=8013
STORAGE_PORT=8011
PRAISE_PROVIDER_PORT=8015
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- MODE=standalone
ports:
- "8848:8848"
- "9848:9848"

# mysql
mysql:
Expand All @@ -34,7 +35,7 @@ services:

# rocketMQ
rmqnamesrv:
image: apache/rocketmq:4.9.4
image: apache/rocketmq:5.3.1
hostname: rocketmq
restart: always
container_name: integrated-example-rmqnamesrv
Expand All @@ -43,29 +44,31 @@ services:
command: sh mqnamesrv

rmqbroker:
image: apache/rocketmq:4.9.4
image: apache/rocketmq:5.3.1
restart: always
container_name: integrated-example-rmqbroker
ports:
- "10909:10909"
- "10911:10911"
- "10912:10912"
volumes:
- ../config-init/rocketmq/broker.conf:/opt/rocketmq-4.9.4/conf/broker.conf
- ../config-init/rocketmq/broker.conf:/opt/rocketmq-5.3.1/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
command: sh mqbroker -c /opt/rocketmq-5.3.1/conf/broker.conf
depends_on:
- rmqnamesrv

# seata
seata-server:
image: seataio/seata-server:1.5.1
image: apache/seata-server:2.1.0
hostname: seata-server
restart: always
container_name: integrated-example-seata-server
ports:
- "7091:7091"
- "8091:8091"
environment:
- SEATA_PORT=8091
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ To ensure that the code can start properly, please configure the local host mapp
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 rocketmq-server
127.0.0.1 gateway-service
127.0.0.1 integrated-frontend
```

> recommend to use host machine's ip, in case run `docker-compose-env.yaml` and `docker-compose-service.yaml` separately,eg depoly env on linux and debug service on windows

### 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.
Expand Down Expand Up @@ -74,7 +76,7 @@ For the distributed transaction capability, we provide the scenario **where a us

#### Start test

Visit `http://integrated-frontend:8080/order` to experience the corresponding scenario.
Visit `http://integrated-frontend:8010/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.

Expand Down Expand Up @@ -111,7 +113,7 @@ For service fusion limiting and peak and valley cutting in the context of high t

- Sentinel service meltdown degradation

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

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

Expand All @@ -123,7 +125,7 @@ Therefore, we can see that Sentinel performs a service fusion on the Gateway sid

- RocketMQ is performing peak and valley reduction

Visit `http://integrated-frontend:8080/rocketmq` to experience the corresponding scenario.
Visit `http://integrated-frontend:8010/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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ To ensure that the code can start properly, please configure the local host mapp
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 rocketmq-server
127.0.0.1 gateway-service
127.0.0.1 integrated-frontend
```

> recommend to use host machine's ip, in case run `docker-compose-env.yaml` and `docker-compose-service.yaml` separately,eg depoly env on linux and debug service on windows

### Database configuration

Before you start the database configuration, please make sure the MySQL server is on.
Expand Down Expand Up @@ -138,7 +140,7 @@ For the distributed transaction capability, we provide the scenario **where a us

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

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

By clicking the order button directly to submit the form, application simulate the client sending a request to the gateway to create an order.

Expand Down Expand Up @@ -177,7 +179,7 @@ Start the `integrated-praise-provider` and `integrated-praise-consumer` modules

- Sentinel service meltdown degradation

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

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

Expand All @@ -189,7 +191,7 @@ Therefore, we can see that Sentinel performs a service fusion on the Gateway sid

- RocketMQ is performing peak and valley reduction

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

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
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 rocketmq-server
127.0.0.1 gateway-service
127.0.0.1 integrated-frontend
```

> 推荐直接使用宿主机ip,避免 `docker-compose-env.yaml` 和 `docker-compose-service.yaml` 运行在不同环境的情况下,出现网络无法连接的情况,例如服务部署在Linux,但在Windows上 debug 应用

### 准备 jar 包

进入 `spring-cloud-alibaba-examples` 目录下,执行 `mvn package` 命令编译项目生成 jar 包,为后续 Docker 构建服务镜像做准备。
Expand Down Expand Up @@ -75,7 +77,7 @@ docker-compose-env.yml 文件运行成功之后,添加 Nacos 配置:

#### 启动测试

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

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

Expand Down Expand Up @@ -112,7 +114,7 @@ docker-compose-env.yml 文件运行成功之后,添加 Nacos 配置:

- Sentinel 服务熔断降级

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

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

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

- RocketMQ 进行流量削峰填谷

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

由于之前在 Nacos 中配置了 `integrated-praise-consumer` 消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
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 rocketmq-server
127.0.0.1 gateway-service
127.0.0.1 integrated-frontend
```

> 推荐直接使用宿主机ip,避免 `docker-compose-env.yaml` 和 `docker-compose-service.yaml` 运行在不同环境的情况下,出现网络无法连接的情况,例如服务部署在Linux,但在Windows上 debug 应用

### 数据库配置

下面开始本地环境搭建准备,在数据库配置开始之前,请确保 MySQL 的服务端开启。
Expand Down Expand Up @@ -137,7 +139,7 @@ sh bin/mqbroker

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

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

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

Expand Down Expand Up @@ -176,7 +178,7 @@ sh bin/mqbroker

- Sentinel 服务熔断降级

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

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

Expand All @@ -188,7 +190,7 @@ sh bin/mqbroker

- RocketMQ 进行流量削峰填谷

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

由于之前在 Nacos 中配置了 `integrated-praise-consumer` 消费者模块的消费速率以及间隔,在点击按钮时应用模拟 1000 个点赞请求,针对 1000 个点赞请求,`integrated-praise-provider`
会将 1000 次请求都向 Broker 投递消息,而在消费者模块中会根据配置的消费速率进行消费,向数据库更新点赞的商品数据,模拟大流量下 RocketMQ 削峰填谷的特性。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ metadata:
spec:
type: NodePort
ports:
- port: 8080
- port: 8010
name: web
targetPort: 8080
targetPort: 8010
nodePort: 30080
selector:
app: integrated-frontend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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"]
command: ["sh","/usr/local/rocketmq-4.8.0/bin/mqbroker", "-n","rocketmq-server:9876"]
imagePullPolicy: IfNotPresent
env:
- name: JAVA_OPT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jdk-alpine as builder
FROM openjdk:17-jdk-alpine AS builder

LABEL author="yuluo" \
email="yuluo829@aliyun.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
import com.alibaba.cloud.integration.common.Result;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

/**
* @author TrevorLink
Expand All @@ -50,7 +46,7 @@ public Result<?> reduceBalance(@RequestBody AccountDTO accountDTO) {
}

@GetMapping("/")
public Result<?> getRemainAccount(String userId) {
public Result<?> getRemainAccount(@RequestParam("userId") String userId) {
return accountService.getRemainAccount(userId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jdk-alpine as builder
FROM openjdk:17-jdk-alpine AS builder

LABEL author="yuluo" \
email="yuluo829@aliyun.com"
Expand All @@ -7,6 +7,6 @@ ADD ./integrated-frontend/target/integrated-frontend-*.jar /app.jar

RUN sh -c 'touch /app.jar'

EXPOSE 8080
EXPOSE 8010

ENTRYPOINT ["java", "-jar", "/app.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring:
application:
name: integrated-frontend

server:
port: 8010
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jdk-alpine as builder
FROM openjdk:17-jdk-alpine AS builder

LABEL author="yuluo" \
email="yuluo829@aliyun.com"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jdk-alpine as builder
FROM openjdk:17-jdk-alpine AS builder

LABEL author="yuluo" \
email="yuluo829@aliyun.com"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jdk-alpine as builder
FROM openjdk:17-jdk-alpine AS builder

LABEL author="yuluo" \
email="yuluo829@aliyun.com"
Expand Down
Loading
Loading