-
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 29, 2024
1 parent
c967bc1
commit ef8cf0f
Showing
6 changed files
with
67 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,63 @@ | ||
--- | ||
title: 第09节:网关上下文属性顶层接口设计 | ||
pay: https://articles.zsxq.com/id_uagjqbe799kd.html | ||
--- | ||
|
||
# 《高性能Polaris网关》通用模型-第09节:网关上下文属性顶层接口设计 | ||
|
||
作者:冰河 | ||
<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网关上下文属性顶层接口的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。 | ||
|
||
## 三、类结构设计 | ||
|
||
为了在保证网关高性能的同时,进一步提升网关的可扩展性,对网关的上下文属性进行设计。上下文属性的顶层接口如图9-1所示。 | ||
|
||
<div align="center"> | ||
<img src="https://binghe.gitcode.host/images/project/gateway/2024-09-29-001.png?raw=true" width="70%"> | ||
<br/> | ||
</div> | ||
|
||
在网关的属性接口设计上,主要设计了PolarisKey和AttributeKey两个接口,其中,PolarisKey是顶层接口,AttributeKey是PoalrisKey的子接口。两个接口中定义的方法含义如下所示。 | ||
|
||
**(1)PolarisKey接口** | ||
|
||
* cast()方法:将Object类型的对象转换成指定的泛型类型。 | ||
|
||
**(2)AttributeKey接口** | ||
|
||
* valueOf()方法:根据转入的名称返回AttributeKey对象。 | ||
* create(final Class<? super T> valueClass)方法:创建AttributeKey对象。 | ||
* getHttpInvoker()方法:获取HttpInvoker对象。 | ||
* getRpcInvoker()方法:获取RpcInvoker对象。 | ||
* getWebSocketInvoker()方法:获取WebSocketInvoker对象。 | ||
* getMatchInstances()方法:获取匹配到的所有服务实例列表。 | ||
* getLoadInstance()方法:获取负载均衡后的服务实例。 | ||
* getAttachment()方法:获取透传的参数。 | ||
|
||
## 四、编码实现 | ||
|
||
接下来,就对网关上下文属性顶层接口进行编码实现。 | ||
|
||
## 查看完整文章 | ||
|
||
加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码 |