Skip to content

Commit a3be0e9

Browse files
author
YunaiV
committed
增加 Zuul 示例
1 parent 4de79d9 commit a3be0e9

File tree

8 files changed

+101
-10
lines changed

8 files changed

+101
-10
lines changed

labx-21/labx-21-sc-zuul-demo07-sentinel/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@
5454
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
5555
</dependency>
5656

57-
<!-- 引入 Spring Cloud Alibaba Nacos Discovery 相关依赖,将 Nacos 作为注册中心,并实现对其的自动配置 -->
58-
<dependency>
59-
<groupId>com.alibaba.cloud</groupId>
60-
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
61-
</dependency>
62-
6357
<!-- 引入 Spring Cloud Alibaba Sentinel 相关依赖,使用 Sentinel 提供服务保障,并实现对其的自动配置 -->
6458
<dependency>
6559
<groupId>com.alibaba.cloud</groupId>

labx-21/labx-21-sc-zuul-demo07-sentinel/src/main/java/cn/iocoder/springcloud/labx21/zuuldemo/CustomBlockFallbackProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CustomBlockFallbackProvider implements ZuulBlockFallbackProvider {
1313

1414
@PostConstruct
1515
public void init() {
16-
ZuulBlockFallbackManager.registerProvider(this);
16+
ZuulBlockFallbackManager.registerProvider(this); // 注册到 ZuulBlockFallbackManager
1717
}
1818

1919
public String getRoute() {

labx-21/labx-21-sc-zuul-demo07-sentinel/src/main/java/cn/iocoder/springcloud/labx21/zuuldemo/ZuulApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class ZuulApplication {
1212

1313
public static void main(String[] args) {
14-
System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_ZUUL_GATEWAY); // 【重点】设置应用类型为 Spring Cloud Gateway
14+
System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_ZUUL_GATEWAY); // 【重点】设置应用类型为 Zuul
1515
SpringApplication.run(ZuulApplication.class, args);
1616
}
1717

labx-21/labx-21-sc-zuul-demo07-sentinel/src/main/resources/application.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spring:
1414
sentinel:
1515
eager: true # 是否饥饿加载。默认为 false 关闭
1616
transport:
17-
dashboard: localhost:7070 # 是否饥饿加载。默认为 false 关闭
17+
dashboard: localhost:7070 # 是否饥饿加载。
1818
# # 数据源的配置项
1919
# datasource:
2020
# ds1.file:
@@ -35,7 +35,7 @@ zuul:
3535
servlet-path: / # ZuulServlet 匹配的路径,默认为 /zuul
3636
# 路由配置项,对应 ZuulRoute Map
3737
routes:
38-
route_yudaoyuanma:
38+
yudaoyuanma: # 这是一个 Route 编号
3939
path: /**
4040
url: http://www.iocoder.cn
4141

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>labx-21</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>labx-21-sc-zuul-demo09-actuator</artifactId>
13+
14+
<properties>
15+
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
16+
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
17+
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version>
18+
</properties>
19+
20+
<!--
21+
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。
22+
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系
23+
-->
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-parent</artifactId>
29+
<version>${spring.boot.version}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.cloud</groupId>
35+
<artifactId>spring-cloud-dependencies</artifactId>
36+
<version>${spring.cloud.version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.alibaba.cloud</groupId>
42+
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
43+
<version>${spring.cloud.alibaba.version}</version>
44+
<type>pom</type>
45+
<scope>import</scope>
46+
</dependency>
47+
</dependencies>
48+
</dependencyManagement>
49+
50+
<dependencies>
51+
<!-- 引入 Spring Cloud Zuul 相关依赖,使用它作为网关,并实现对其的自动配置 -->
52+
<dependency>
53+
<groupId>org.springframework.cloud</groupId>
54+
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
55+
</dependency>
56+
</dependencies>
57+
58+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cn.iocoder.springcloud.labx21.zuuldemo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
6+
7+
@SpringBootApplication
8+
@EnableZuulProxy // 开启 Zuul 网关
9+
public class ZuulApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(ZuulApplication.class, args);
13+
}
14+
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
server:
2+
port: 8888
3+
4+
spring:
5+
application:
6+
name: zuul-application
7+
8+
# Zuul 配置项,对应 ZuulProperties 配置类
9+
zuul:
10+
servlet-path: / # ZuulServlet 匹配的路径,默认为 /zuul
11+
12+
management:
13+
endpoints:
14+
web:
15+
exposure:
16+
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
17+
endpoint:
18+
# Health 端点配置项,对应 HealthProperties 配置类
19+
health:
20+
enabled: true # 是否开启。默认为 true 开启。
21+
show-details: ALWAYS # 何时显示完整的健康信息。默认为 NEVER 都不展示。可选 WHEN_AUTHORIZED 当经过授权的用户;可选 ALWAYS 总是展示。
22+
server:
23+
port: 18888 # 单独设置端口,因为 8888 端口全部给 Zuul 了

labx-21/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<module>labx-21-sc-zuul-demo05-custom-zuul-filter</module>
2020
<module>labx-21-sc-zuul-demo07-hystrix</module>
2121
<module>labx-21-sc-zuul-demo07-sentinel</module>
22+
<module>labx-21-sc-zuul-demo09-actuator</module>
2223

2324
<module>labx-21-sc-user-service</module>
2425
</modules>

0 commit comments

Comments
 (0)