-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
binghe001
committed
Sep 24, 2024
1 parent
86f19f1
commit ee1b163
Showing
6 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: 第06节:网关配置规则模型实现类设计 | ||
pay: https://articles.zsxq.com/id_fnpiq7jtk9oj.html | ||
--- | ||
|
||
# 《高性能Polaris网关》通用模型-第06节:网关配置规则模型实现类设计 | ||
|
||
作者:冰河 | ||
<br/>星球:[http://m6z.cn/6aeFbs](http://m6z.cn/6aeFbs) | ||
<br/>博客:[https://binghe.gitcode.host](https://binghe.gitcode.host) | ||
<br/>文章汇总:[https://binghe.gitcode.host/md/all/all.html](https://binghe.gitcode.host/md/all/all.html) | ||
<br/>源码获取地址:[https://t.zsxq.com/0dhvFs5oR](https://t.zsxq.com/0dhvFs5oR) | ||
|
||
> 沉淀,成长,突破,帮助他人,成就自我。 | ||
* 本章难度:★★☆☆☆ | ||
* 本节重点:对高性能Polaris网关的配置规则模型实现类进行设计,从全局角度掌握高性能Polaris网关配置规则的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
**大家好,我是冰河~~** | ||
|
||
网关的规则是可配置的,也就是说,最终我们自己手写的网关规则是可通过配置中心进行配置和管理的,并且在配置中心修改对应的规则后,程序会立即生效。所以,需要对高性能Polaris网关的配置规则模型类进行设计,以便满足网关的可视化配置需求。 | ||
|
||
## 一、前言 | ||
|
||
在前面的章节中,已经对高性能Polaris网关的请求与响应模型的顶层接口进行了设计,对请求模型和响应模型的顶层接口进行了实现,对调用链路的顶层接口与抽象类进行了设计,并且对调用链路的顶层接口实现类进行了设计。接下来,我们就对网关配置模型的实现类进行设计。 | ||
|
||
## 二、本节诉求 | ||
|
||
对高性能Polaris网关的配置规则模型实现类进行设计,从全局角度掌握高性能Polaris网关配置规则的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
## 三、规则模型类设计 | ||
|
||
网关配置规则模型实现类设计如图6-1所示。 | ||
|
||
<div align="center"> | ||
<img src="https://binghe.gitcode.host/images/project/gateway/2024-09-24-001.png?raw=true" width="70%"> | ||
<br/> | ||
</div> | ||
|
||
可以看到,在设计网关的配置类时,我们将其抽象出FilterRule和Rule两个类。 | ||
|
||
* FilterRule:网关过滤规则,主要是针对网关接口级别、实例级别、服务级别的过滤规则,提供两个核心字段,一个是id,一个是config。 | ||
* id:过滤规则id,唯一标识过滤规则。 | ||
* config:过滤规则配置项内容,json格式的具体配置内容。 | ||
* Rule:Rule类是网关规则配置类,封装网关的核心配置规则,后续会将Rule类封装的数据配置到配置中心,主要包含如下核心字段: | ||
* id:规则配置id,唯一标识规则配置。 | ||
* name: 规则的名称,自定义的名称。 | ||
* protocol:规则的协议,例如:http、rpc、websocket等。 | ||
* serviceId:后端服务的id。 | ||
* prefix:请求的path前缀,例如/api/user/* | ||
* paths:接口的集合。 | ||
* order:排序的规则,网关会根据order进行排序,按先后顺序执行规则。 | ||
* filterRules:网关过滤规则列表。 | ||
|
||
## 四、编码实现 | ||
|
||
接下来,就对网关配置规则模型实现类进行编码实现。 | ||
|
||
## 查看完整文章 | ||
|
||
加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码 |