前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微服务网关基础组件 - zuul入门

微服务网关基础组件 - zuul入门

作者头像
lyb-geek
发布2018-07-26 10:18:45
5760
发布2018-07-26 10:18:45
举报
文章被收录于专栏:Linyb极客之路Linyb极客之路

一、zuul简介

1、作用

zuul使用一系列的filter实现以下功能

  • 认证和安全 - 对每一个resource进行身份认证
  • 追踪和监控 - 实时观察后端微服务的TPS、响应时间,失败数量等准确的信息
  • 日志 - 记录所有请求的访问日志数据,可以为日志分析和查询提供统一支持
  • 动态路由 - 动态的将request路由到后端的服务上去
  • 压力测试 - 逐渐的增加访问集群的压力,来测试集群的性能
  • 限流 - allocating capacity for each type of request and dropping requests that go over the limit
  • 静态响应 - 直接在网关返回一些响应,而不是通过内部的服务返回响应

2、组件:

  • zuul-core:library which contains the core functionality of compiling and executing Filters
  • zuul-netflix:library which adds other NetflixOSS components to Zuul - using Ribbon for routing requests, for example.

3、例子:

  • zuul-simple-webapp:webapp which shows a simple example of how to build an application with zuul-core
  • zuul-netflix-webapp:webapp which packages zuul-core and zuul-netflix together into an easy to use package

github地址:https://github.com/Netflix/zuul/

二、zuul filter

1、关键元素

  • Type:most often defines the stage during the routing flow when the Filter will be applied (although it can be any custom string)
    • 值可以是:pre、route、post、error、custom
  • Execution Order: filter执行的顺序(applied within the Type, defines the order of execution across multiple Filters)
  • Criteria:filter执行的条件(the conditions required in order for the Filter to be executed)
  • Action: filter执行的动作(the action to be executed if the Criteria is met)

注意点:

  • filters之间不会直接进行通讯交流,他们通过一个RequestContext共享一个state
    • 该RequestContext对于每一个request都是唯一的
  • filter当前使用groovy来写的,也可以使用java
  • The source code for each Filter is written to a specified set of directories on the Zuul server that are periodically polled for changes
  • zuul可以动态的read, compile, and run these Filters
    • 被更新后的filter会被从disk读取到内存,并动态编译到正在运行的server中,之后可以用于其后的每一个请求(Updated filters are read from disk, dynamically compiled into the running server, and are invoked by Zuul for each subsequent request)

2、filter type(与一个典型的request的生命周期相关的filter type)

  • PRE Filters
    • request authentication
    • choosing origin servers(选机器)
    • logging debug info.
    • 限流
    • 执行时机: before routing to the origin.
    • 这类filter可能做的事
  • ROUTING Filters
    • 这类filter可能做的事:真正的向service的一台server(这台server是pre filter选出来的)发请求,handle routing the request to an origin,This is where the origin HTTP request is built and sent using Apache HttpClient or Netflix Ribbon.
  • POST Filters
    • adding standard HTTP headers to the response
    • gathering statistics and metrics
    • streaming the response from the origin to the client
    • 执行时机:after the request has been routed to the origin
    • 这类filter可能做的事
  • ERROR Filters
    • 执行时机:其他三个阶段任一阶段发生错误时执行(when an error occurs during one of the other phases)
  • CUSTOM Filters
    • 沿着默认的filter流,zuul允许我们创建一些自定义的Filter type,并且准确的执行他们。
    • 例如:我们自定义一个STATIC type的filter,用于从zuul直接产生响应,而不是从后边的services(we have a custom STATIC type that generates a response within Zuul instead of forwarding the request to an origin)

三、zuul request lifecycle(filter流)

说明:对应(二)的filter type来看

四、zuul核心架构

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-06-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Linyb极客之路 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档