EdgeX Foundry -- Geneva版本 -- 配置文件说明

配置文件说明

这些微服务的配置文件的结构都大同小异,edgex-go中微服务的结构在 /internal/具体服务/config/config.go文件中,下面是core-data,和metadata的配置结构。

// metadata
type ConfigurationStruct struct {
	Writable      WritableInfo
	Clients       map[string]bootstrapConfig.ClientInfo
	Databases     map[string]bootstrapConfig.Database
	Logging       bootstrapConfig.LoggingInfo
	Notifications NotificationInfo
	Registry      bootstrapConfig.RegistryInfo
	Service       bootstrapConfig.ServiceInfo
	SecretStore   bootstrapConfig.SecretStoreInfo
	Startup       bootstrapConfig.StartupInfo
}
// core-data
type ConfigurationStruct struct {
	Writable     WritableInfo
	MessageQueue MessageQueueInfo
	Clients      map[string]bootstrapConfig.ClientInfo
	Databases    map[string]bootstrapConfig.Database
	Logging      bootstrapConfig.LoggingInfo
	Registry     bootstrapConfig.RegistryInfo
	Service      bootstrapConfig.ServiceInfo
	SecretStore  bootstrapConfig.SecretStoreInfo
	Startup      bootstrapConfig.StartupInfo
}

可以看到,不同微服务的配置结构中有一些常用的信息,如Clients, Registry, Logging, Service, SecretStore, Startup等,这些信息的结构都是统一的,在go-mod-bootstrap/config中定义。

也有一些信息是要根据微服务的功能来自定义的结构,如Writeable, Notification, MessageQueue等等,基本每个服务都有Writeable结构,但起具体内容是每个微服务自定义的,这部分内容就具体问题具体分析了。注意Writeable配置的内容可通过consul-ui实时的修改,而其他结构的内容也可通过consul-ui修改,但要重启服务才能生效

下面介绍常用结构的内容:

Service

// ServiceInfo contains configuration settings necessary for the basic operation of any EdgeX service.
type ServiceInfo struct {
	// BootTimeout indicates, in milliseconds, how long the service will retry connecting to upstream dependencies
	// before giving up. Default is 30,000.
	BootTimeout int
	// Health check interval
	CheckInterval string
	// Indicates the interval in milliseconds at which service clients should check for any configuration updates
	ClientMonitor int
	// Host is the hostname or IP address of the service.
	Host string
	// Port is the HTTP port of the service.
	Port int
	// The protocol that should be used to call this service
	Protocol string
	// StartupMsg specifies a string to log once service
	// initialization and startup is completed.
	StartupMsg string
	// MaxResultCount specifies the maximum size list supported
	// in response to REST calls to other services.
	MaxResultCount int
	// Timeout specifies a timeout (in milliseconds) for
	// processing REST calls from other services.
	Timeout int
}

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
}

服务注册的信息,edgex-go 中所有微服务都要注册到consul,所以这里需要提供consulhost, port信息,Type是因为之前版本使用其他的服务管理工具,为了兼容设置的,现在填consul就好。

Logging

// LoggingInfo provides basic parameters related to where logs should be written.
type LoggingInfo struct {
	EnableRemote bool		// 是否使用远程日志,
	File         string
}

日志模块,如果不启用远程日志的话,就直接将日志输出到stdout

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
}

注意配置Clientsmap[string]bootstrapConfig.ClientInfo,所以可以保存多个ClientInfo结构。

有些微服务的设计上就需要与其他微服务进行通信,因此需要知道其他微服务的Host:Port、协议等信息。如core-data 要通过metadata验证设备是否存在,因此需要metadata的信息。

Databases

type Database struct {
	Username string
	Password string
	Type     string		// 新版本推荐 redis,以前使用 mongo
	Timeout  int
	Host     string
	Port     int
	Name     string
}

metadata, coredata 等模块并不是自己维护一个数据库,而是有一个专门的数据库edgex-redis,由metadata这些微服务提供 将特定数据存入数据库,或者向数据库查询数据的方法。凡是需要向这样直接对数据库进行操作的微服务,都需要与数据库建立连接,因此也就需要知道数据库的Host, Port, password信息,至于 Username 等信息,是使用Mongo才会用到的,redis 并不会使用(见edgex-go/internal/pkg/bootstrap/handlers/database/database.go: newDBClient())。

数据库数据样例

SecretStore

// SecretStoreInfo encapsulates configuration properties used to create a SecretClient.
type SecretStoreInfo struct {
	Host                    string
	Port                    int
	Path                    string
	Protocol                string
	Namespace               string
	RootCaCertPath          string
	ServerName              string
	Authentication          vault.AuthenticationInfo
	AdditionalRetryAttempts int
	RetryWaitPeriod         string
	retryWaitPeriodTime     time.Duration
	// TokenFile provides a location to a token file.
	TokenFile string
}

Startup

// StartupInfo provides the startup timer values which are applied to the StartupTimer created at boot.
type StartupInfo struct {
	Duration int
	Interval int
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值