spring cloud网关zuul源码之Filter管理
来源:互联网 发布:显卡满载测试软件 编辑:程序博客网 时间:2024/05/29 14:36
接上一篇request管理。
原文地址:http://blog.csdn.net/haha7289/article/details/54344150
zuul支持动加载Filter类文件。实现原理是监控存放Filter文件的目录,定期扫描这些目录,如果发现有新Filter源码文件或者Filter源码文件有改动,则对文件进行编译加载。目前zuul支持使用Groovy编写的Filter。
FilterFileManager
FilterFileManager
用于管理Filter存放目录,并定期扫描目录的变化。
他的功能如下:
- 开启一个线程,开始轮询
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 每次轮询,处理目录内的所有*.groovy文件,即调用
FilterLoader.getInstance().putFilter(file);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
FilterLoader
编译、加载filter文件,并且检查源文件是否有变更,除此之外,它还按照filterType
组织并维护List<ZuulFilter>
主要逻辑
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
这里主要的逻辑是把Groovy源码进行编译并加载进jvm里。
FilterRegistry
用于管理加载的filter,数据结构比较简单,使用 ConcurrentHashMap<String, ZuulFilter> filters
,启动key为filter的name:file.getAbsolutePath() + file.getName();
DynamicCodeCompiler
是一个接口,定义两种加载编译源码的方法:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
总结
zuul整体框架比较简单,如果要实现API-Gateway,或者client-api adapter code,可以参考下。框架背后的思想也许更值得我们参考。
参考
- Announcing Zuul: Edge Service in the Cloud
- Building Microservices: Using an API Gateway
- Embracing the Differences : Inside the Netflix API Redesign
- Pattern: API Gateway
- Optimizing the Netflix API
0 0
- spring cloud网关zuul源码之Filter管理
- spring cloud网关zuul之filter注册
- spring cloud网关zuul源码Request生命周期管理
- Spring Cloud(七)服务网关 Zuul Filter 使用
- Spring Cloud Zuul--服务网关
- Spring Cloud Zuul--服务网关
- 服务网关 Spring Cloud Zuul
- Spring Cloud微服务(3)之网关Zuul
- spring cloud之zuul路由网关(六)
- zuul源码分析之Filter管理
- spring cloud 之 zuul
- spring cloud 之 zuul
- Spring Cloud Zuul (服务网关)
- spring-cloud-zuul服务网关(五)
- 五、Spring Cloud 的 Zuul 网关组件
- API网关服务:Spring Cloud Zuul
- Spring Cloud学习--服务网关(Zuul)
- Spring Cloud学习--服务网关(Zuul 过滤器)
- svn图标会存在延迟怎么办?还有不出现图标怎么办?
- Caffe GNU error
- 日志分片工具cronolog
- 第十六章 循环运行的例行性工作排程
- 用Python做测试——利用模块进行集中管理
- spring cloud网关zuul源码之Filter管理
- 第十六章 可唤醒停机期间的工作任务(anacron)
- mysql Multiversion Concurrency Control机制(mvcc)
- 折半查找
- 第十七章 什么是程序 (Process)
- Android Binder 全解析(1) -- 概述
- 第十七章 工作管理 (job control)
- 第十七章 程序管理
- printf中%p的输出应用