zuul

什么是zuul?

摘自官网:

Zuul is the front door for all requests from devices and web sites to the backend of the Netflix streaming application. As an edge service application, Zuul is built to enable dynamic routing, monitoring, resiliency and security. It also has the ability to route requests to multiple Amazon Auto Scaling Groups as appropriate.

英语不太好,我用百度翻译一下:

Zuul是从设备和网站到Netflix流媒体应用程序后端的所有请求的前门。作为一个边缘服务应用程序,Zuul被构建为支持动态路由、监视、弹性和安全性。它还可以根据需要将请求路由到多个Amazon自动伸缩组。

看了看还是没看懂,哈哈哈哈哈,简单来说就是路由和过滤。

为什么使用?

上面我们可以说已经解决了服务之前的通信问题,但现在还有一个问题,我们提供者服务一般不直接给消费者真正的地址的,上面都是写的真实的访问地址,为了安全,我们可以通过zuul来实现路由,当然zuul不仅可以做路由,还可以做过滤器等等。

路由功能

实现zuul路由很简单,通过@ZuulProxy注解开启。

  • 在demo_configuration中添加Pom依赖

    1. 1 <!-- zuul -->
    2. 2 <dependency>
    3. 3 <groupId>org.springframework.cloud</groupId>
    4. 4 <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    5. 5 </dependency>
    6. 复制代码
  • yml配置文件,设置路由规则

    1server:
    2  port: 9001
    3
    4spring:
    5  application:
    6    name: user
    7
    8info:
    9  name: lytw13
    10  web: lytw13.top
    11
    12eureka:
    13  client:
    14    service-url:
    15      defaultZone: http://localhost:6001/eureka/
    16    fetch-registry: true
    17    register-with-eureka: true
    18  instance:
    19    instance-id: zuul01
    20    ip-address: true
    21zuul:
    22  prefix: /lytw13  #统一前缀
    23  routes:
    24    web.serverId: web
    25    web.path: /userWeb/**
    复制代码
    

    测试:
    SpringCloud之服务网关Zuul(五) - 图1zuul_route_ceshi1.png
    作者:lytw1315
    链接:https://juejin.im/post/5dfb5d28f265da33b07182c7
    来源:掘金
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。