美文网首页
Zuul使用指南

Zuul使用指南

作者: 莫看烟雨 | 来源:发表于2018-08-20 20:50 被阅读0次

maven依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>

springboot2.0以上版本,多了个netflix

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>

添加注解

EnableZuulProxy是zuul和euraka自动集成,EnableZuulServer是单独的zuul服务器。

@SpringBootApplication
@EnableZuulProxy

添加默认配置

默认自动转发请求到euraka中对应的service上。

eureka:
  instance:
    preferIpAddress: true
client:
  registerWithEureka: true
  fetchRegistry: true
  serviceUrl:
     defaultZone: http://localhost:8761/eureka/

查看转发配置

5555为zuul的默认端口号,可自行更改。

http://localhost:5555/routes

TIPS:使用 routes 端点的前提:

Zuul Server需要有Spring Boot Actuator的依赖,否则访问 /routes 端点将会返回404;。

设置 management.security.enabled=false ,否则将会返回401;也可添加Spring Security的依赖,这样可通过账号、密码访问 routes 端点。

配置

参考类:
org.springframework.cloud.netflix.zuul.filters.ZuulProperties

其中ignoredServices配置为'*',表示启用白名单模式,即屏蔽掉所有的euraka中的服务,需要通过routes来进行转发模式匹配。

filter分类

pre/post/route
prefilter适合鉴权及认证,
routefilter适合来修改请求地址及其它信息,适合处理灰度环境(A/Btest)
postfilter适合记录日志。

相关文章

网友评论

      本文标题:Zuul使用指南

      本文链接:https://www.haomeiwen.com/subject/wihriftx.html