-
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 25, 2024
1 parent
ee1b163
commit e3039e1
Showing
6 changed files
with
62 additions
and
1 deletion.
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,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)知识星球,解锁完整技术文章、小册、视频与完整代码 |