site/src/base/initialize.md

366 lines
7.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Initialize 初始化微服务
## 介绍
Initialize 微服务负责在初始化数据、检测新版本或新的配置、获取应用的相关配置信息、系统区域数据、系统标签数据等其它应用相关数据。
## 源码仓库
```
https://git.apinb.com/bsm-service-base/initialize
```
## 安装
要安装 Initialize 初始化微服务,请确保您已经安装了 bsm cli, 安装命令如下:
```bash
bsm install initialize
```
## 配置文件
`etc/` 目录中根据dev,test,prod环境不同读取不同的配置文件通过配置微服务决定是否启用相关服务例如
initialize_prod.yaml
```yaml
Name: {ServiceKey}
ListenOn: 0.0.0.0:12202
Dsn: postgres://postgres:******@127.0.0.1:5432/{Workspace}_prod?sslmode=disable&TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:******@127.0.0.1:6379/
Etcd:
Hosts:
- 127.0.0.1:2379
Key: service.{Workspace}.{ServiceKey}.rpc
# 匿名访问清单,自动注入网关层
Anonymous:
Key: anonymous.{Workspace}
Urls:
- initialize.Check.Hello
- initialize.Check.Updates
- initialize.Data.Configure
- initialize.Data.Areas
- initialize.Data.Tags
# 日志记录, 注释将不启用此功能
Log:
ServiceName: {ServiceKey}
Mode: file
Path: logs/{ServiceKey}
Stat: false
# 性能监控, 注释将不启用此功能
Prometheus:
Host: 127.0.0.1
Port: 22202
Path: /metrics
# 链路追踪, 注释将不启用此功能
Telemetry:
Name: {Workspace}.{ServiceKey}.{RuntimeMode}
Endpoint: http://127.0.0.1:14268/api/traces
Sampler: 1.0
Batcher: jaeger
# MQ Pulsar, 不启用
#Pulsar:
# Endpoints: 127.0.0.1
# Token: 9091
# Namespaces: {Workspace}
```
## 管理微服务
使用以下命令管理微服务:
```bash
bsm start/restart/update initialize
```
## API 接口说明
### 检测是否有新版或新的配置
POST /initialize.Check.Updates
> Body 请求参数
```json
{
"app": "ut occaecat sit Duis proident",
"os": "consequat laborum velit reprehenderit",
"arch": "exercitation sit reprehenderit in amet",
"version": "minim ullamco"
}
```
#### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|Request-Id|header|string| 是 ||请求ID|
|Content-Type|header|string| 是 ||传输格式|
|Workspace|header|string| 是 ||项目名称|
|Authorization|header|string| 否 ||用户通行证Token|
|body|body|object| 否 ||none|
|» app|body|string| 是 | 应用程序名称 <必填>|应用程序名称|
|» os|body|string| 是 | 操作系统 <必填>|操作系统|
|» arch|body|string| 是 | 构架名称 <必填>|构架名称|
|» version|body|string| 是 | 版本号 <必填>|版本号|
> 返回示例
> 200 Response
```json
{
"identity": "string",
"version": "string",
"summary": "string",
"files": "string",
"pubdate": "string"
}
```
#### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
#### 返回数据结构
状态码 **200**
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» identity|string|true|none|唯一标识|0为未找到相应版本|
|» version|string|true|none|版本号|0为未找到相应版本|
|» summary|string|true|none||none|
|» files|string|true|none||none|
|» pubdate|string|true|none||none|
### 获取应用的相关配置信息
POST /initialize.Data.Configure
> Body 请求参数
```json
{
"app": "milu",
"os": "windows"
}
```
#### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|Content-Type|header|string| 是 ||none|
|Request-Id|header|string| 是 ||请求ID|
|Workspace|header|string| 是 ||项目名称|
|Authorization|header|string| 否 ||用户通行证Token|
|body|body|object| 否 ||none|
|» app|body|string| 是 | 应用程序名称 <必填>|应用程序名称|
|» os|body|string| 是 | 操作系统 <必填>|操作系统|
> 返回示例
> 200 Response
```json
{}
```
#### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
#### 返回数据结构
状态码 **200**
*empty object*
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
### 获取系统区域数据
POST /initialize.Data.Areas
> Body 请求参数
```json
{}
```
#### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|Content-Type|header|string| 是 ||none|
|Request-Id|header|string| 是 ||请求ID|
|Workspace|header|string| 是 ||项目名称|
|Authorization|header|string| 否 ||用户通行证Token|
|body|body|object| 否 ||none|
|» is_town|body|boolean| 否 ||是否列出乡镇数据,【开关】|
> 返回示例
> 200 Response
```json
{
"areas": [
{
"id": "string",
"pid": "string",
"deep": 0,
"name": "string",
"pinyinPrefix": "string",
"pinyin": "string",
"extId": "string",
"extName": "string"
}
]
}
```
#### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
#### 返回数据结构
状态码 **200**
*empty object*
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» areas|[object]|true|none||区域数据数组|
|»» id|string|true|none||none|
|»» pid|string|true|none||none|
|»» deep|integer|true|none||none|
|»» name|string|true|none||none|
|»» pinyinPrefix|string|true|none||none|
|»» pinyin|string|true|none||none|
|»» extId|string|true|none||none|
|»» extName|string|true|none||none|
### 获取系统标签数据
POST /initialize.Data.Tags
> Body 请求参数
```json
{}
```
#### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|Content-Type|header|string| 是 ||none|
|Request-Id|header|string| 是 ||请求ID|
|Workspace|header|string| 是 ||项目名称|
|Authorization|header|string| 否 ||用户通行证Token|
|body|body|object| 否 ||none|
> 返回示例
> 200 Response
```json
{
"tags": [
"string"
]
}
```
#### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
#### 返回数据结构
状态码 **200**
*empty object*
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» tags|[string]|true|none||标签数据数组|
### hello
POST /initialize.Check.Hello
> Body 请求参数
```json
{}
```
#### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|Request-Id|header|string| 是 ||请求ID|
|Content-Type|header|string| 是 ||传输格式|
|Workspace|header|string| 是 ||项目名称|
|Authorization|header|string| 否 ||用户通行证Token|
|body|body|object| 否 ||none|
> 返回示例
> 200 Response
```json
{
"Code": 0,
"Data": {
"identity": "string",
"status": "string",
"message": "string",
"timeseq": "string"
}
}
```
#### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
#### 返回数据结构
状态码 **200**
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» Code|integer|true|none||none|
|» Data|object|true|none||none|
|»» identity|string|true|none||none|
|»» status|string|true|none||none|
|»» message|string|true|none||none|
|»» timeseq|string|true|none||none|