Skip to content

Commit 04bc047

Browse files
author
YunaiV
committed
增加 spring cloud gateway 网关的示例
1 parent 2ff9136 commit 04bc047

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

labx-08/labx-08-sc-gateway-demo07-sentinel/src/main/java/cn/iocoder/springcloud/labx08/gatewaydemo/CustomBlockRequestHandler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class CustomBlockRequestHandler implements BlockRequestHandler {
1515

1616
@Override
1717
public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable ex) {
18-
return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS)
19-
.contentType(MediaType.TEXT_PLAIN)
20-
.bodyValue(DEFAULT_BLOCK_MSG_PREFIX + ex.getClass().getSimpleName());
18+
return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS) // 状态码
19+
.contentType(MediaType.TEXT_PLAIN) // 内容类型为 text/plain 纯文本
20+
.bodyValue(DEFAULT_BLOCK_MSG_PREFIX + ex.getClass().getSimpleName()); // 错误提示
2121
}
2222

2323
}

labx-08/labx-08-sc-gateway-demo07-sentinel/src/main/java/cn/iocoder/springcloud/labx08/gatewaydemo/GatewayApplication.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
public class GatewayApplication {
88

99
public static void main(String[] args) {
10+
// System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_SCG_GATEWAY);
11+
// System.setProperty(SentinelConfig.APP_TYPE, "1");
1012
SpringApplication.run(GatewayApplication.class, args);
1113
}
1214

labx-08/labx-08-sc-gateway-demo07-sentinel/src/main/resources/application.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ spring:
1919
eager: true # 是否饥饿加载。默认为 false 关闭
2020
transport:
2121
dashboard: localhost:7070 # 是否饥饿加载。默认为 false 关闭
22-
# 数据源的配置项
23-
datasource:
24-
ds1.file:
25-
file: "classpath: sentinel-gw-flow.json"
26-
ruleType: gw-flow
27-
ds2.file:
28-
file: "classpath: sentinel-gw-api-group.json"
29-
ruleType: gw-api-group
22+
# # 数据源的配置项
23+
# datasource:
24+
# ds1.file:
25+
# file: "classpath: sentinel-gw-flow.json"
26+
# ruleType: gw-flow
27+
# ds2.file:
28+
# file: "classpath: sentinel-gw-api-group.json"
29+
# ruleType: gw-api-group
3030
# Sentinel 对 Spring Cloud Gateway 的专属配置项,对应 SentinelGatewayProperties 类
3131
scg:
32-
order:
32+
order: -2147483648 # 过滤器顺序,默认为 -2147483648 最高优先级
3333
fallback:
3434
mode: # fallback 模式,目前有三种:response、redirect、空
3535
# 专属 response 模式

0 commit comments

Comments
 (0)