site/src/base/initialize.md

7.5 KiB
Raw Blame History

Initialize 初始化微服务

介绍

Initialize 微服务负责在初始化数据、检测新版本或新的配置、获取应用的相关配置信息、系统区域数据、系统标签数据等其它应用相关数据。

源码仓库

https://git.apinb.com/bsm-service-base/initialize

安装

要安装 Initialize 初始化微服务,请确保您已经安装了 bsm cli, 安装命令如下:

bsm install initialize

配置文件

etc/ 目录中根据dev,test,prod环境不同读取不同的配置文件通过配置微服务决定是否启用相关服务例如

initialize_prod.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}

管理微服务

使用以下命令管理微服务:

bsm start/restart/update initialize

API 接口说明

检测是否有新版或新的配置

POST /initialize.Check.Updates

Body 请求参数

{
  "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

{
  "identity": "string",
  "version": "string",
  "summary": "string",
  "files": "string",
  "pubdate": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 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 请求参数

{
  "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

{}

返回结果

状态码 状态码含义 说明 数据模型
200 OK none Inline

返回数据结构

状态码 200

empty object

名称 类型 必选 约束 中文名 说明

获取系统区域数据

POST /initialize.Data.Areas

Body 请求参数

{}

请求参数

名称 位置 类型 必选 中文名 说明
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

{
  "areas": [
    {
      "id": "string",
      "pid": "string",
      "deep": 0,
      "name": "string",
      "pinyinPrefix": "string",
      "pinyin": "string",
      "extId": "string",
      "extName": "string"
    }
  ]
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 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 请求参数

{}

请求参数

名称 位置 类型 必选 中文名 说明
Content-Type header string none
Request-Id header string 请求ID
Workspace header string 项目名称
Authorization header string 用户通行证Token
body body object none

返回示例

200 Response

{
  "tags": [
    "string"
  ]
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK none Inline

返回数据结构

状态码 200

empty object

名称 类型 必选 约束 中文名 说明
» tags [string] true none 标签数据数组

hello

POST /initialize.Check.Hello

Body 请求参数

{}

请求参数

名称 位置 类型 必选 中文名 说明
Request-Id header string 请求ID
Content-Type header string 传输格式
Workspace header string 项目名称
Authorization header string 用户通行证Token
body body object none

返回示例

200 Response

{
  "Code": 0,
  "Data": {
    "identity": "string",
    "status": "string",
    "message": "string",
    "timeseq": "string"
  }
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 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