简介
- Zuul是Spring Cloud全家桶中的微服务API网关。 所有从设备或网站来的请求都会经过Zuul到达后端的Netflix应用程序
- Zuul 主要提供路由(请求转发)和过滤
- Zuul 最终会注入Eureka
提供: 代理,过滤和路由三大功能
使用
导入依赖
?
|
1
2
3
4
5
6
7
8
9
10
11
|
<!--zuul组件、zuul需要注册至eureka中-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
|
配置文件
?
|
1
2
3
4
5
6
7
8
9
10
11
12
|
server:
port: 9527
spring:
application:
name: springcloud-zuul
eureka:
client:
service-url:
defaultZone: http://eureka1:7001/eureka/,http://eureka2:7002/eureka/,http://eureka3:7003/eureka/
instance:
instance-id: zull9527.com #别名
|
开启支持
?
|
1
2
3
4
5
6
7
|
@SpringBootApplication
@EnableZuulProxy//开启zuul支持,默认注册到Eureka
public class Zuul9527Application {
public static void main(String[] args) {
SpringApplication.run(Zuul9527Application.class,args);
}
}
|
此时我们可以通过 地址:端口号/服务名称/服务 来访问了
注意:此处需在host文件添加 127.0.01 www,zuultest.com

为了不使我们的服务名称暴露我们可以在配置文件中添加
?
|
1
2
3
4
5
6
|
zuul:
routes:
xxx.serviceId: provider-name # xxx代表任意名称
xxx.path: /mydept/**
ignored-services: provider-name # 不再通过这个路径访问即不允许通过服务名直接访问
prefix: /lin # 访问路径必须加上前缀/lin
|
此时只有通过 地址:端口号/lin/mydept/服务 来访问
补充: 为什么在配置文件中是使用serviceId和path 在zull中route是以键值对的形式存放的
?
|
1
2
3
|
public void setRoutes(Map<String, ZuulRoute> routes) {
this.routes = routes;
}
|
而在ZuulProperties中
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/**
* Represents a Zuul route.
*/
public static class ZuulRoute {
/**
* The path (pattern) for the route, e.g. /foo/**.
*/
private String path;
/**
* The service ID (if any) to map to this route. You can specify a physical URL or
* a service, but not both.
*/
private String serviceId;
}
|
以上就是SpringCloud Zuul的使用简介的详细内容,更多关于SpringCloud Zuul的使用的资料请关注快网idc其它相关文章!
原文链接:https://juejin.cn/post/6951321316200808479
相关文章
猜你喜欢
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 52
-
2025-05-29 65
-
2025-06-04 52
-
2025-05-25 42
-
windows系统控制面板中"internet信息服务IIS管理器"的解决办法(internet 信息服务)
2025-05-25 44
热门评论


