EDGEX FOUNDRY配置参数 --- config-seed

config-seed应该在其他EDGEX FOUNDRY核心微服务(不包括数据库和consul服务)之前被启动,他的作用是把已经写好的相应配置文件写入consul服务以便后面的微服务启动的时候能够拉取相对应的配置参数。config-seed主要上传两类配置参数:EDGEX FOUNDRY核心微服务自身启动所需的配置参数和应用服务的配置属性参数。

config-seed的使用介绍如下,他有5个启动参数可以配置:

  • confdir是配置文件profile路径的上级目录,默认为空则为环境变量EDGE_CONF_DIR的值,若未设置该环境变量则为'./res'即可执行文件所在目录下的res目录
  • profile是config-seed自身启动所需一个toml 格式的文件所在文件夹的路径,配置文件的名字必须是configuration.toml。则最终配置文件的绝对路径是:[confdir]/configuration.toml(若未设置profile), 或[confdir]/[profile]/configuration.toml
  • props是一个文件夹路径,存放了应用服务的配置文件,配置文件多是properties后缀结尾的文件。
  • cmd是一个文件夹路径,存放了EDGEX FOUNDRY核心微服务启动的配置文件,这些配置文件一般是toml格式。
  • override是一个bool变量,他指示config-seed是否覆盖掉consul中已经存在的KV对。
Usage: %s [options]
Server Options:
    --confdir                       Specify local configuration directory
    -p, --profile <name>            Indicate configuration profile other than default
    -r, --props <dir>               Provide alternate location for legacy application.properties files
    -c, --cmd <dir>                 Provide absolute path to "cmd" directory containing EdgeX services
    -o, --override <bool>           Overwrite configuration in Registry
Common Options:
    -h, --help                      Show this message

Table of Contents

config-seed配置文件(--profile)

微服务的配置参数(--cmd)

应用的配置属性参数(--props)


  • config-seed配置文件(--profile)

ConfigPath = './config'
GlobalPrefix = 'config'
IsReset = true
FailLimit = 30
FailWaitTime = 3
AcceptablePropertyExtensions = ['.toml','.yaml', '.yml', '.properties']
YamlExtensions = ['.yaml','.yml']
TomlExtensions = ['.toml']
EnableRemoteLogging = false
LoggingFile = './logs/edgex-config-seed.log'
LoggingRemoteURL = 'http://localhost:48061/api/v1/logs'
LoggingLevel = 'INFO'

[Registry]
Host = 'localhost'
Port = 8500
Type = 'consul'

上图是项目自带的config-seed的配置文件 ,主要分两块:基础配置参数和注册服务(consul)参数。config-seed启动后会从-p参数找到该配置文件路径并将配置文件的内容载入到如下结构中,

type ConfigurationStruct struct {
	ConfigPath                   string
	GlobalPrefix                 string
	IsReset                      bool
	FailLimit                    int
	FailWaitTime                 int
	AcceptablePropertyExtensions []string
	YamlExtensions               []string
	TomlExtensions               []string
	EnableRemoteLogging          bool
	LoggingFile                  string
	LoggingRemoteURL             string
	LoggingLevel                 string
	Registry                     config.RegistryInfo
}
ConfigPath                   string
GlobalPrefix                 Consul中KEY值的根名
IsReset                      bool
FailLimit                    int
FailWaitTime                 int
AcceptablePropertyExtensions 可接受的文件后缀,导入Properties时遍历目录下的文件时会过滤掉后缀不在该列表中的文件
YamlExtensions               Yaml文件支持的的后缀名
TomlExtensions               Toml文件支持的后缀名
EnableRemoteLogging          是否将log存储在远程Logging微服务中
LoggingFile                  本地log文件存储绝对路径
LoggingRemoteURL             edgex-support-logging地址,如:http://edgex-support-logging:48061/api/v1/logs
LoggingLevel                 Log等级,INFO,DEBUG, ...
Registry                     Registry服务配置参数
// RegistryInfo defines the type and location (via host/port) of the desired service registry (e.g. Consul, Eureka)
type RegistryInfo struct {
	Host string
	Port int
	Type string
}
Host consul服务地址
Port consul服务端口
Type 注册服务类型(目前仅支持consul)
  • 微服务的配置参数(--cmd)

微服务配置文件目录结构

目前共有9个核心微服务可以配置,这些微服务的配置文件的组织方式和项目源码中的存放结构一致如上图所示,cmd启动参数指定顶层文件夹的路径,config-seed会遍历[cmd]下的所有文件夹并从其下搜寻对应的配置文件,如上图该路径下面有9个文件夹,文件夹的名字就是微服务的名字,这些文件夹下面均存在一个子文件夹res,然后下面存放了配置文件configuration.toml;若profile启动参数有设置(假设设置为docker),则将在res/docker/下面寻找配置文件。因此最终配置文件的绝对路径是: [cmd]/[microservice-name]/res/configuration.toml(若profile没有配置),或[cmd]/[microservice-name]/res/[profile]/configuration.toml

Configuration在consul中key的名字:

edgex/core/1.0/edgex-[Service Name]/[Name]

edgex/core/1.0/edgex-   在代码中被硬编码不可修改

Service Name是微服务的名字即[cmd]下的文件夹名字,如:core-command, core-data...

Name是配置文件中的key值。如support-logging微服务的配置文件中

[Registry]
Host = 'localhost'

Name的值是Registry/Host, 最终consul中KV对是edgex/core/1.0/edgex-support-logging/Registry/Host = 'localhost'

Config-seed中的启动参数overwrite可决定是否覆盖consul中已经存在的KV。

  • 应用的配置属性参数(--props)

Properties配置文件组织结构

红色方框是放置Properties文件的根目录,config-seed启动的时候将该路径传给-props或-p。该目录下面则存放各个应用服务的配置文件,每个应用服务单独一个文件夹,文件夹的名字则是该应用的Service Key,文件夹下面可存放多个与该应用服务相关的配置文件,配置文件的后缀名必须要在AcceptablePropertyExtensions 中。配置文件的格式必须是[key]=[Value], 如下图所示,

Properties配置文件示例

Properties在consul中key的名字:

[GlobalPrefix]/[Service Key]/[Name]

GlobalPrefix是config-seed配置文件中设置。

Service Key是应用配置目录的名字,即上图橙色方框中的名字。

Name是配置文件中key的名字,如上图绿色方框所示。

最上图的配置文件中能够框处的内容为例,其在consul中的KV对是:

config/device-virtual;docker/logging.level.org.springframework = ERROR

猜你喜欢

转载自blog.csdn.net/keyoushide/article/details/89163358