Skip to content

Commit

Permalink
feature: 高性能Polaris网关项目-环境搭建-第08节
Browse files Browse the repository at this point in the history
  • Loading branch information
binghe001 committed Sep 28, 2024
1 parent e3039e1 commit c967bc1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
* [《高性能Polaris网关》通用模型-第05节:调用链路顶层接口的实现类设计](https://articles.zsxq.com/id_s6ddb045x0uk.html)
* [《高性能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)

### 💥 分布式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 @@ -1609,6 +1609,7 @@ function getBarGateway(){
"model/2024-09-23-chapter05.md",
"model/2024-09-24-chapter06.md",
"model/2024-09-25-chapter07.md",
"model/2024-09-28-chapter08.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 @@ -297,6 +297,7 @@ title: 冰河指南
* [《高性能Polaris网关》通用模型-第05节:调用链路顶层接口的实现类设计](https://articles.zsxq.com/id_s6ddb045x0uk.html)
* [《高性能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)

### 💥 分布式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 @@ -274,6 +274,7 @@ title: 冰河指南
* [《高性能Polaris网关》通用模型-第05节:调用链路顶层接口的实现类设计](https://articles.zsxq.com/id_s6ddb045x0uk.html)
* [《高性能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)

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

Expand Down
59 changes: 59 additions & 0 deletions docs/md/project/gateway/model/2024-09-28-chapter08.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: 第08节:服务配置缓存接口与实现类模型设计
pay: https://articles.zsxq.com/id_c6amcv1qjks8.html
---

# 《高性能Polaris网关》通用模型-第08节:服务配置缓存接口与实现类模型设计

作者:冰河
<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网关服务配置缓存接口与实现类的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。

**大家好,我是冰河~~**

为了提高网关的性能,网关除了需要通过配置中心来配置网关的核心规则外,在网关内部也会设计服务配置的缓存模型来缓存一些核心配置,例如,在网关内部,会缓存唯一id和服务定义的映射关系、唯一id与服务实例列表的映射关系、配置规则id与配置规则的映射关系、请求路径与服务规则的映射关系以及服务与规则列表的映射关系等。

## 一、前言

在前面的章节中,已经对高性能Polaris网关的请求与响应模型的顶层接口进行了设计,对请求模型和响应模型的顶层接口进行了实现,对调用链路的顶层接口与抽象类进行了设计,对调用链路的顶层接口实现类和网关配置模型的实现类进行了设计。随后,又对网关服务的定义与实例模型类进行了设计。接下来,就对服务配置的缓存接口与实现类进行设计。

## 二、本节诉求

对高性能Polaris网关的服务配置缓存接口与实现类进行设计,从全局角度掌握高性能Polaris网关服务配置缓存接口与实现类的设计。重点掌握整体调用链路的设计思路和设计方法,并能够将其灵活应用到自身实际项目中。

## 三、类结构设计

网关内部服务配置缓存接口与实现类的模型设计如图8-1所示。

<div align="center">
<img src="https://binghe.gitcode.host/images/project/gateway/2024-09-28-001.png?raw=true" width="70%">
<br/>
</div>

可以看到,在网关内部的服务配置缓存接口与实现类模型的设计中,主要设计了一个ConfigCache接口、一个ContextConfigCache实现类和一个ConfigCacheFactory工厂类,其中,SingletonHolder类是ConfigCacheFactory工厂类的内部类,每个类的简单说明如下所示。

* ConfigCache接口:服务配置缓存接口,定义了服务配置缓存的常用方法,主要涉及到缓存唯一id和服务定义的映射关系、唯一id与服务实例列表的映射关系、配置规则id与配置规则的映射关系、请求路径与服务规则的映射关系以及服务与规则列表的映射关系等。
* ContextConfigCache实现类:ConfigCache接口的实现类,实现了ConfigCache接口中定义的方法,并将对应的缓存数据存储到ContextConfigCache实现类内部定义的ConcurrentMap中。
* ConfigCacheFactory工厂类:提供了一个静态方法getInstance(),返回内部类SingletonHolde中定义的常量INSTANCE,也就是返回ConfigCache对象。这里使用了单例设计模式。
* SingletonHolder内部类:SingletonHolder类是ConfigCacheFactory工厂类的内部类,主要定义了一个ConfigCache类型的常量INSTANCE,与ConfigCacheFactory工厂类一起实现了单例模式。

## 四、编码实现

接下来,就对服务配置接口与实现类模型进行编码实现。

**(1)实现ConfigCache接口**

ConfigCache接口是网关内部的配置缓存接口。

源码详见:polaris-context工程下的io.binghe.polaris.context.cache.ConfigCache。

## 查看完整文章

加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码

0 comments on commit c967bc1

Please sign in to comment.