本帖最后由 keer_zu 于 2020-12-18 10:45 编辑
EDGEX FOUNDRY配置参数 --- support-scheduler
support-scheduler是主要是EDGEX系统中的提醒服务,support-scheduler使用介绍如下,他有2个启动参数可以配置: - registry是一个bool量,True表示support-scheduler的配置参数是从consul拉取,False表示从本地配置文件载入。
- profile本地配置文件的路径, 即便registry=True, 该参数也必须要指明一个配置文件,因为连接consul服务所需的host,port等参数必须从本地的配置文件中获取
Usage: %s [options]
Server Options:
-r, --registry Indicates service should use Registry
-p, --profile <name> Indicate configuration profile other than default
Common Options:
-h, --help Show this message
Table of Contents
support-scheduler的配置文件 Writable Clients Databases Logging Registry Service Intervals IntervalActions
support-scheduler的配置文件
[Writable]
ScheduleIntervalTime = 500
LogLevel = 'INFO'
[Service]
BootTimeout = 30000
ClientMonitor = 15000
CheckInterval = '10s'
Host = 'localhost'
Port = 48085
Protocol = 'http'
ReadMaxLimit = 100
StartupMsg = 'This is the Support Scheduler Microservice'
Timeout = 5000
[Registry]
Host = 'localhost'
Port = 8500
Type = 'consul'
[Logging]
EnableRemote = false
File = './logs/edgex-support-scheduler.log'
[Clients]
[Clients.Logging]
Protocol = 'http'
Host = 'localhost'
Port = 48061
[Databases]
[Databases.Primary]
Host = 'localhost'
Name = 'scheduler'
Password = ''
Port = 27017
Username = ''
Timeout = 5000
Type = 'mongodb'
[Intervals]
[Intervals.Midnight]
Name = 'midnight'
Start = '20180101T000000'
Frequency = 'P1D'
[IntervalActions]
[IntervalActions.ScrubPushed]
Name = 'scrub-pushed-events'
Host = 'localhost'
Port = 48080
Protocol = 'http'
Method = 'DELETE'
Target = 'core-data'
Path = '/api/v1/event/scrub'
Interval = 'midnight'
[IntervalActions.ScrubAged]
Name = 'scrub-aged-events'
Host = 'localhost'
Port = 48080
Protocol = 'http'
Method = 'DELETE'
Target = 'core-data'
Path = '/api/v1/event/removeold/age/604800000'
Interval = 'midnight'
如上是项目自带的support-scheduler的配置文件 ,主要分8部分,support-scheduler启动后会将配置文件的信息导入如下结构中,若registry=True则根据Registry中的信息连接consul并拉取相应的配置信息覆盖之前从本地配置文件中读取到的信息。
// Configuration V2 for the Support Scheduler Service
type ConfigurationStruct struct {
Writable WritableInfo
Clients map[string]config.ClientInfo
Databases map[string]config.DatabaseInfo
Logging config.LoggingInfo
Registry config.RegistryInfo
Service config.ServiceInfo
Intervals map[string]config.IntervalInfo
IntervalActions map[string]config.IntervalActionInfo
}
Writable
type WritableInfo struct {
ScheduleIntervalTime int
LogLevel string
}
support-scheduler有2个参数可以在运行时被修改
ScheduleIntervalTime 内部定时器间隔触发时间,单位:毫秒
LogLevel 日志等级
Clients
// ClientInfo provides the host and port of another service in the eco-system.
type ClientInfo struct {
// Host is the hostname or IP address of a service.
Host string
// Port defines the port on which to access a given service
Port int
// Protocol indicates the protocol to use when accessing a given service
Protocol string
}
Host 微服务的地址
Port 微服务的端口
Protocol 微服务所使用的协议,目前仅支持http
support-scheduler运行时需要使用其他微服务提供的功能,Client便是连接其他微服务所必须的参数,这是一个map参数,key值便是其他微服务的名字,value便是client的具体参数信息, support-scheduler正常运行一般需要使用logging微服务。
Databases
type DatabaseInfo struct {
Type string
Timeout int
Host string
Port int
Username string
Password string
Name string
}
Type 数据库类型,目前仅支持 mongodb
Timeout 数据库连接超时,单位:s
Host 数据库地址
Port 数据库端口
Username 数据库登录用户名
Password 数据库登录密码
Name 数据库名字
support-scheduler当前支持两种Primary数据库mongodb和redisdb。
Logging
// LoggingInfo provides basic parameters related to where logs should be written.
type LoggingInfo struct {
EnableRemote bool
File string
}
EnableRemote True: log于support-logging微服务持久化(support-logging的连接参数由Clients字段提供), False:log于本地文件持久化
File log本地持久化时日志文件的路径
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
}
consul连接参数
Service 同support-logging Intervals
type IntervalInfo struct {
// Name of the schedule must be unique?
Name string
// Start time in ISO 8601 format YYYYMMDD'T'HHmmss
Start string
// End time in ISO 8601 format YYYYMMDD'T'HHmmss
End string
// Periodicity of the schedule
Frequency string
// Cron style regular expression indicating how often the action under schedule should occur. Use either runOnce, frequency or cron and not all.
Cron string
// Boolean indicating that this schedules runs one time - at the time indicated by the start
RunOnce bool
}
Interval是触发的描述结构,support-scheduler会周期性的检查Interval数组并将满足触发条件的Interval过滤出来,执行下挂在其下的所有触发动作。Interval的来源主要有三处:
1,support-scheduler使用的数据库,support-scheduler启动时会从数据库load已经存在的Interval
2,配置文件,support-scheduler会载入配置文件中的Interval并将其写入数据库持久化,值得注意的是support-scheduler不支持重名的 Interval,因此当配置文件的Interval的Name与数据库中的相应Interval的Name相同时会优先使用数据库中的Interval而放弃配置文件中的Interval
3,support-scheduler提供的restful API接口支持动态更新Interval信息
Name 触发 名字
Start 触发开始时间 ISO 8601 format YYYYMMDD'T'HHmmss
End 触发结束时间 ISO 8601 format YYYYMMDD'T'HHmmss
Frequency 周期性触发时的触发频率
Cron Cron 风格的触发表达式
RunOnce 是否仅仅触发一次
IntervalActions
type IntervalActionInfo struct {
// Host is the hostname or IP address of a service.
Host string
// Port defines the port on which to access a given service
Port int
// Protocol indicates the protocol to use when accessing a given service
Protocol string
// Action name
Name string
// Action http method *const prob*
Method string
// Acton target name
Target string
// Action target parameters
Parameters string
// Action target API path
Path string
// Associated Schedule for the Event
Interval string
}
触发动作的执行最终都表现为访问一个外部服务(外部指的是support-scheduler微服务的外部),可以是core-data等其他微服务,也可以是其他接口兼容的服务。Host 外部服务主机名
Port 外部服务端口
Protocol 外部服务协议,目前仅支持http
Name 触发动作的名字
Method http方法,GET,POST等等
Target 外部服务的名字
Parameters http参数,目前源码不支持该字段
Path 外部服务path 如/api/v1/event/removeold/age/604800000
Interval 绑定的Interval名字,非常关键,如果该字段在support-scheduler中没有对应的Interval也就意味着该触发动作永远不会被执行
出处:原文
|