FoghostCn commented on issue #2432:
URL: https://github.com/apache/dubbo-go/issues/2432#issuecomment-1786377625
# Metadata模块优化 draft
- MetadataService 本地及对外暴露元数据接口
```go
// 从 ServiceDiscovery 列表中获取元数据信息
type MetadataService interface {
// 服务段暴露的接口 url
GetExportedServiceURLs() ([]*common.URL, error)
// 客户端订阅的接口 url
GetSubscribedURLs() ([]*common.URL, error)
// metadata 版本号
Version() (string, error)
// 获取本地服务发现的 metadataInfo,用于对外暴露,客户端可以通过这个接口获取应用 metadataInfo
GetMetadataInfo(revision string) (*MetadataInfo, error)
// 获取本地所有的服务发现的 metadataInfo 列表
getMetadataInfos()[]*MetadataInfo
// 获取 metadataService 服务的 url 参数
GetMetadataServiceURL() (*common.URL, error)
}
```
- MetadataInfo 存储 servicediscovery 相关元数据容器
```go
type MetadataInfo struct {
Reported bool `json:"-"`
App string `json:"app,omitempty"`
Revision string
`json:"revision,omitempty"`
Services map[string]*ServiceInfo
`json:"services,omitempty"`
exportedServiceURLs map[string]gxset.HashSet
subscribedServiceURLs map[string]gxset.HashSet
}
// 服务端 添加一个service 的 url,一个应用可以有多个服务暴露,一个接口可以有多个协议暴露
func (info *MetadataInfo) AddService(url *common.URL) (bool, error) {
}
// 服务端 删除一个 service 的 url 元数据
func (info *MetadataInfo) RemoveService(url *common.URL) error {
}
// 客户端 订阅一个 服务的 url 元数据
func (info *MetadataInfo) AddSubscribeURL(url *common.URL) (bool, error) {
}
// 客户端 删除一个订阅的服务 url 元数据
func (info *MetadataInfo) RemoveSubscribeURL(url *common.URL) error{
}
```
- ServiceDiscovery 的 metadata 接口
```go
// register/subscribe 时将元数据写入自身 metadataInfo,
// unregister/unsubscribe 时移除 metadataInfo 中相关内容
type ServiceDiscovery interface {
// 返回本地服务元数据
GetLocalMetadata() *MetadataInfo;
// 从本地缓存获取,否则从 MetadataReport 获取,否则从 rpc MetadataService 获取
GetRemoteMetadata(revision string) *MetadataInfo
}
```
- MetadataReport 接口
```go
// 接口均为应用级服务发现使用
type MetadataReport interface {
// GetAppMetadata get metadata info from report
// zookeeper: /dubbo/metadata/dubbo.io/${revision}
GetAppMetadata(*identifier.SubscriberMetadataIdentifier)
(*MetadataInfo, error)
// PublishAppMetadata publish metadata info to reportss
// zookeeper: /dubbo/metadata/dubbo.io/${revision}
PublishAppMetadata(*identifier.SubscriberMetadataIdentifier,
*MetadataInfo) error
// RegisterServiceAppMapping map the specified Dubbo service interface
to current Dubbo app name
// zookeeper:
/dubbo/mapping/org.apache.dubbo.samples.api.GreetingsService
RegisterServiceAppMapping(key string, group string, content string)
error
// GetServiceAppMapping get the app names from the specified Dubbo
service interface
// zookeeper:
/dubbo/mapping/org.apache.dubbo.samples.api.GreetingsService
GetServiceAppMapping(key string, group string, MappingListener)
(*gxset.HashSet, error)
// RemoveServiceAppMappingListener remove the serviceMapping listener
by key and group
// zookeeper:
/dubbo/mapping/org.apache.dubbo.samples.api.GreetingsService
RemoveServiceAppMappingListener(key string, group string) error
}
```
- 元数据中心数据维护流程
```go
Server:
start -> export -> register -> PublishAppMetadata &&
RegisterServiceAppMapping
Client:
start -> refer -> subscribe -> GetServiceAppMapping && GetAppMetadata
->
stop -> unsubscribe -> RemoveServiceAppMappingListener
```
- 目录调整:
```
common
├── extension
│ ├── metadata_remote.go // 取消扩展接口,操作远程 Metadata
│ ├── metadata_report_factory.go
│ ├── metadata_service.go // 取消扩展接口, MetadataService 本身
│ ├── metadata_service_exporter.go // 取消扩展接口 MetadataService 暴露方式
│ ├── metadata_service_proxy_factory.go // 取消扩展接口,rpc 调用 MetadataService
├── metadata_info.go // move to metadata 目录
config
├── instance // move to metadata 目录
│ ├── metadata_report.go // MetadataReport 实例化,全局缓存
│ ├── registry_metadata_report.go // registry 相关 MetadataReport 缓存
├── metadata_report_config.go // 配置相关实体
metadata
├── definition // 删除,不再需要
│ ├── definition.go // 实体定义 provider metadata
│ └── mock.go
├── identifier // move to metadata/report metadataReport 接口参数定义
│ ├── base_metadata_identifier.go
│ ├── metadata_identifier.go
│ ├── service_metadata_identifier.go
│ ├── subscribe_metadata_identifier.go
├── mapping
│ ├── memory
│ │ └── service_name_mapping.go
│ ├── metadata
│ │ └── service_name_mapping.go
│ ├── mock_service_name_mapping.go
│ └── service_name_mapping.go
├── report // MetadataReport 各种实现
│ ├── delegate
│ │ ├── delegate_report.go
│ ├── etcd
│ │ ├── report.go
│ ├── factory
│ │ └── report_factory.go
│ ├── nacos
│ │ ├── report.go
│ ├── report.go
│ ├── reporter_metric.go
│ └── zookeeper
│ └── report.go
└── service // 整体上移到 metadata 目录
├── exporter // MetadataService export as service
│ ├── configurable
│ │ ├── exporter.go
│ └── exporter.go // MetadataService 暴露接口定义,可扩展自定义实现?
├── local
│ ├── metadata_service_proxy_factory.go
│ ├── service.go
│ ├── service_proxy.go // rpc 获取 metadataInfo,可以简化实现,
│── service_test.go
├── local_service.go
├── remote
│ ├── service.go
└── remote_service.go // 应用级服务发现使用
```
- 调整后目录:
```
common
├── extension
│ ├── metadata_report_factory.go
config
├── metadata_report_config.go
metadata
├── metadata_info.go
├── configurableExporter.go // MetadataService 暴露接口定义,取消 extension 扩展
├── service.go // MetadataService 实现类
├── service_proxy.go // rpc 式调用 metadataService 接口,取消 extension 扩展
├── metadata_service.go // MetadataService 接口定义
├── mapping
│ ├── metadata
│ │ └── service_name_mapping.go
│ └── service_name_mapping.go
├── report
| ├── identifier
| │ ├── base_metadata_identifier.go
| │ ├── metadata_identifier.go
| │ ├── service_metadata_identifier.go
| │ ├── subscribe_metadata_identifier.go
│ ├── etcd
│ │ ├── report.go
│ ├── factory
│ │ └── report_factory.go
│ ├── nacos
│ │ └── report.go
| ├── zookeeper
| │ └── report.go
│ ├── delegate_report.go
│ ├── report.go
│ └── reporter_metric.go // metrics 相关,融入到基类或者 delegate_report
```
备注:
服务发现 zk 示例,路径 /services/{appName}/{IP}:{PORT}
```json
{
"name": "metrics-provider",
"id": "10.253.77.49:20880",
"address": "10.253.77.49",
"port": 20880,
"sslPort": null,
"payload": {
"@class": "org.apache.dubbo.registry.zookeeper.ZookeeperInstance",
"id": "10.253.77.49:20880",
"name": "metrics-provider",
"metadata": {
"dubbo.endpoints": "[{\"port\":20880,\"protocol\":\"dubbo\"}]",
"dubbo.metadata-service.url-params":
"{\"prefer.serialization\":\"fastjson2,hessian2\",\"version\":\"1.0.0\",\"dubbo\":\"2.0.2\",\"release\":\"3.2.1\",\"side\":\"provider\",\"port\":\"20881\",\"protocol\":\"dubbo\"}",
"dubbo.metadata.revision": "a12dcb4cf2519a7aa7cc2539a256648e",
"dubbo.metadata.storage-type": "local",
"timestamp": "1698398778406"
}
},
"registrationTimeUTC": 1698403384382,
"serviceType": "DYNAMIC",
"uriSpec": null
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]