Skip to content

Commit

Permalink
feature: 高性能Polaris网关项目-通用模型-第09节
Browse files Browse the repository at this point in the history
  • Loading branch information
binghe001 committed Sep 29, 2024
1 parent c967bc1 commit ef8cf0f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
* [《高性能Polaris网关》通用模型-第06节:网关配置规则模型实现类设计](https://articles.zsxq.com/id_fnpiq7jtk9oj.html)
* [《高性能Polaris网关》通用模型-第07节:服务定义与实例模型实现类设计](https://articles.zsxq.com/id_pj75f0kbekoi.html)
* [《高性能Polaris网关》通用模型-第08节:服务配置缓存接口与实现类模型设计](https://articles.zsxq.com/id_c6amcv1qjks8.html)
* [《高性能Polaris网关》通用模型-第09节:网关上下文属性顶层接口设计](https://articles.zsxq.com/id_uagjqbe799kd.html)

### 💥 分布式IM即时通讯系统

Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@ function getBarGateway(){
"model/2024-09-24-chapter06.md",
"model/2024-09-25-chapter07.md",
"model/2024-09-28-chapter08.md",
"model/2024-09-29-chapter09.md",
]
}
]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/md/all/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ title: 冰河指南
* [《高性能Polaris网关》通用模型-第06节:网关配置规则模型实现类设计](https://articles.zsxq.com/id_fnpiq7jtk9oj.html)
* [《高性能Polaris网关》通用模型-第07节:服务定义与实例模型实现类设计](https://articles.zsxq.com/id_pj75f0kbekoi.html)
* [《高性能Polaris网关》通用模型-第08节:服务配置缓存接口与实现类模型设计](https://articles.zsxq.com/id_c6amcv1qjks8.html)
* [《高性能Polaris网关》通用模型-第09节:网关上下文属性顶层接口设计](https://articles.zsxq.com/id_uagjqbe799kd.html)

### 💥 分布式IM即时通讯系统

Expand Down
1 change: 1 addition & 0 deletions docs/md/other/guide-to-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ title: 冰河指南
* [《高性能Polaris网关》通用模型-第06节:网关配置规则模型实现类设计](https://articles.zsxq.com/id_fnpiq7jtk9oj.html)
* [《高性能Polaris网关》通用模型-第07节:服务定义与实例模型实现类设计](https://articles.zsxq.com/id_pj75f0kbekoi.html)
* [《高性能Polaris网关》通用模型-第08节:服务配置缓存接口与实现类模型设计](https://articles.zsxq.com/id_c6amcv1qjks8.html)
* [《高性能Polaris网关》通用模型-第09节:网关上下文属性顶层接口设计](https://articles.zsxq.com/id_uagjqbe799kd.html)

### 💥 分布式IM即时通讯系统

Expand Down
63 changes: 63 additions & 0 deletions docs/md/project/gateway/model/2024-09-29-chapter09.md
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)知识星球,解锁完整技术文章、小册、视频与完整代码

0 comments on commit ef8cf0f

Please sign in to comment.