1.ZUUL是一种网关技术。 2.所有的URL均不对外暴露,只留下网关作为对外的唯一接口。 3.请求使用网关对外提供的路由,经过网关的解析转发到对应接口,进行调度和过滤。 4.高级使用: 1).路由规则 2).熔断机制 3).服务聚合 总结:ZUUL通过路由规则配置,隐蔽接口,通过相应的规则,将请求转发到对应的接口。ZUUL的搭建:(新建一个Eureka客户端项目:)
1.添加依赖:
org.springframework.cloud spring-cloud-starter-netflix-eureka-clientorg.springframework.cloud spring-cloud-starter-netflix-zuul2.2.10.RELEASE com.netflix.zuul zuul-core1.3.0
2.配置文件:
server:
port: 9100
spring:
application:
name: zuul
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/ #当前zuul网关想要注册到哪个注册中心
#路由规则定义。这里定义两种路由规则route1和route2
#,代表访问网关/test01hello/**
routes:
user-service:
path: /user-service/**
user-service:
service-id=user-service
3).经过如上设置,访问 http://localhost:port/user-service/hello后将无法找到该请求。
5.路由前缀
zuul:
routes:
#自定义实例名称
api-user:
#路由配置
path: /user/**
#注册中心中的服务id
service-id: user-service
#截断前缀设置
strip-prefix: false
**(经过如上设置,路由前缀不会被ZUUL自动截断)**
ZUUL通配符:
/** :匹配任意数量的路径与字符 /client/add,/client/a,/client/a/b/c /* :匹配任意数量的字符 /client/add,/client/a,/client/abc /? :匹配单个字符 /client/a,/client/b,/client/c总结:
1.ZUUL类似于一种URL过滤及转发器,将请求由网关统一进行调配。 2.如果请求URL符合网关中的配置,则转发到相应的请求。 3.如果不符合,即被网关过滤。



