Skip to content

Commit

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

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

Expand Down
3 changes: 2 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ module.exports = {
text: "中间件项目",
items:[
{
text: '手写高性能Polaris网关',
text: '手写高性能Polaris网关(新)',
link: '/md/project/gateway/start/2024-05-19-start.md'
},
{
Expand Down Expand Up @@ -1608,6 +1608,7 @@ function getBarGateway(){
"model/2024-09-22-chapter04.md",
"model/2024-09-23-chapter05.md",
"model/2024-09-24-chapter06.md",
"model/2024-09-25-chapter07.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 @@ -296,6 +296,7 @@ title: 冰河指南
* [《高性能Polaris网关》通用模型-第04节:调用链路顶层接口与抽象类设计](https://articles.zsxq.com/id_tfnwsj54urvg.html)
* [《高性能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)

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

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

Expand Down
57 changes: 57 additions & 0 deletions docs/md/project/gateway/model/2024-09-25-chapter07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: 第07节:服务定义与实例模型实现类设计
pay: https://articles.zsxq.com/id_pj75f0kbekoi.html
---

# 《高性能Polaris网关》通用模型-第07节:服务定义与实例模型实现类设计

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

## 三、实现类设计

服务定义与实例模型实现类设计如图7-1所示。

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

可以看到,对于网关的服务定义和服务实例来说,设计了ServiceDefinition类和ServiceInstance类,其中,ServiceDefinition类是服务定义类,ServiceInstance类是服务实例类,具体说明如下所示。

ServiceDefinition类在设计上包含如下字段:

* uniqueId:服务定义的唯一id,在设计上由serviceId:version组成。
* serviceId:服务id,标识一个服务。
* version:服务的版本号。
* protocol:服务的具体协议:例如,http/rpc/websocket
* patternPath:路径匹配规则。
* envType:环境的名称,在部署网关时,需要支持开发、测试、压测、体验、生产等环境。
* enable:标识服务是否启用,true:启用;false:不启用。
* invokerMap:服务invokerPath与服务调用的映射关系,key是服务的invokerPath,value是服务调用ServiceInvoker对象。

ServiceInstance类在设计上包含如下字段:

## 查看完整文章

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

0 comments on commit e3039e1

Please sign in to comment.