-
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.
feature: 高性能Polaris网关项目-环境搭建-第04~05节
- Loading branch information
binghe001
committed
Sep 22, 2024
1 parent
88afb3f
commit 86f19f1
Showing
8 changed files
with
112 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.
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,50 @@ | ||
--- | ||
title: 第04节:调用链路顶层接口与抽象类设计 | ||
pay: https://articles.zsxq.com/id_tfnwsj54urvg.html | ||
--- | ||
|
||
# 《高性能Polaris网关》通用模型-第04节:调用链路顶层接口与抽象类设计 | ||
|
||
作者:冰河 | ||
<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网关的请求与响应模型的顶层接口进行了设计,也对请求模型和响应模型的顶层接口进行了实现。至此,我们已经从整体上了解了高性能Poalris网关的请求与响应数据模型,也了解了请求模型和响应模型的顶层接口的实现方案。接下来,就对调用链路的顶层接口与抽象类进行设计。 | ||
|
||
## 二、本节诉求 | ||
|
||
对高性能Polaris网关的调用链路的顶层接口和抽象类进行设计,从全局角度掌握高性能Polaris网关整体调用链路的核心链路设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
## 三、顶层接口设计 | ||
|
||
调用链路顶层接口与抽象类设计如图4-1所示。 | ||
|
||
<div align="center"> | ||
<img src="https://binghe.gitcode.host/images/project/gateway/2024-09-22-001.png?raw=true" width="70%"> | ||
<br/> | ||
</div> | ||
|
||
可以看到,在整个顶层调用链路中,我们进行了高度抽象化的设计。在最顶层设计了PolarisInvoker接口,在PoalrisInvoker接口中,主要设计了获取和设置调用链路信息的方法以及获取和设置超时时间的方法。随后,设计了ServiceInvoker接口继承自PolarisInvoker接口,在ServiceInvoker接口中,主要设计了获取和设置规则id的方法。同时,设计了AbstractServiceInvoker抽象类,实现了ServiceInvoker接口,在AbstractServiceInvoker抽象类中,主要定义了invokerPath、ruleId和timeout三个字段,随后实现了PolarisInvoker和ServiceInvoker接口中定义的方法。 | ||
|
||
## 四、编码实现 | ||
|
||
接下来,就对调用链路顶层接口与抽象类进行编码实现。 | ||
|
||
## 查看完整文章 | ||
|
||
加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码 |
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,54 @@ | ||
--- | ||
title: 第05节:调用链路顶层接口的实现类设计 | ||
pay: https://articles.zsxq.com/id_s6ddb045x0uk.html | ||
--- | ||
|
||
# 《高性能Polaris网关》通用模型-第05节:调用链路顶层接口的实现类设计 | ||
|
||
作者:冰河 | ||
<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网关整体调用链路的核心链路设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
## 三、顶层实现类设计 | ||
|
||
调用链路顶层接口实现类设计如图5-1所示。 | ||
|
||
<div align="center"> | ||
<img src="https://binghe.gitcode.host/images/project/gateway/2024-09-23-001.png?raw=true" width="70%"> | ||
<br/> | ||
</div> | ||
|
||
可以看到,在设计顶层实现类时,我们会为AbstractServiceInvoker类设计三个实现类,分别为HttpServiceInvoker类、RpcServiceInvoker类和WebSocketServiceInvoker类。其中,HttpServiceInvoker类是调用HTTP服务的类,RpcServiceInvoker类是调用RPC服务的类,WebSocketServiceInvoker类是调用WebSocket服务的类。 | ||
|
||
## 四、编码实现 | ||
|
||
接下来,就对调用链路顶层接口的实现类进行编码实现。 | ||
|
||
**(1)实现HttpServiceInvoker类** | ||
|
||
HttpServiceInvoker类是调用HTTP服务的类。 | ||
|
||
源码详见:polaris-context工程下的io.binghe.polaris.context.invoker.HttpServiceInvoker。 | ||
|
||
## 查看完整文章 | ||
|
||
加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码 |