Documentation ¶
Index ¶
- Constants
- func EventEngine(conf backends.StoreConfig) eventEngine
- func NewStoreConfig() (conf backends.StoreConfig)
- type ChangedListener
- type Configuration
- type EndpointCacher
- type Event
- func (e *Event) AddData(key string, value interface{}) *Event
- func (e Event) GeKey() string
- func (e Event) GePubTime() int64
- func (e *Event) GetData(key string) interface{}
- func (e *Event) IsOverloaded() bool
- func (e Event) IsPublished() bool
- func (e Event) IsTimeout() bool
- func (e Event) Json() ([]byte, error)
- func (e *Event) SetPubTime(pubTime int64) *Event
- func (e *Event) SetPublished() *Event
- type EventListener
- type Processor
Constants ¶
const DesKey = "aluka-7!"
const Namespace = "/system"
Variables ¶
This section is empty.
Functions ¶
func EventEngine ¶
func EventEngine(conf backends.StoreConfig) eventEngine
func NewStoreConfig ¶
func NewStoreConfig() (conf backends.StoreConfig)
NewStoreConfig 提供给所有业务系统使用的配置管理引擎,所有业务系统/中间件的可变配置通过集中配置中心进行统一 配置,业务系统可通过该类来管理 自己的配置数据并在配置中心的数据发生变化时得到及时的通知。
配置管理中心的数据存储为树形目录结构(类似文件系统的目录结构),每一个节点都可以存储相应的数据。业务系统可在基础目录树的基础上 往下继续扩展新的目录结构,从而可以区分存储不同的配置项信息。比如系统分配给业务系统A的基础目录(称为path)为/sysa, 那么业务系统可以扩充到如下path:/sysa/key1、/sysa/key2、/sysa/key3,每个path可存储对应的数据。
配置管理引擎客户端依赖连接的配置管理中心,需要在同一配置管理中心下载对应的授权文件方可。
Types ¶
type ChangedListener ¶
type ChangedListener interface { // Changed 指定配置变化后的通知接口,标示变化的路径和变化后的data(变化后的新数据值)。 Changed(data map[string]string) }
ChangedListener 配置数据发生变化时的监听器接口。
type Configuration ¶
type Configuration interface { Values(app, group, tag string, path []string) (map[string]string, error) String(app, group, tag, path string) (string, error) Clazz(app, group, tag, path string, clazz interface{}) error Get(app, group, tag string, path []string, parser ChangedListener) Watch(app, group, tag, path string, callback EndpointCacher) Lock(app, group, tag, path string) *zk.Lock Add(app, group, tag, path string, value []byte, flags int32) (string, error) Modify(app, group, tag, path string, value []byte) error Delete(app, group, tag, path string) error }
func DefaultEngine ¶
func DefaultEngine() Configuration
func MockEngine ¶
func MockEngine(t *testing.T, conf backends.StoreConfig) Configuration
type EndpointCacher ¶ added in v1.0.4
type Event ¶
type Event struct { Key string `json:"key"` // 事件的唯一key PubTime int64 `json:"pub_time"` // 事件的发布时间,单位毫秒 Timeout int64 `json:"timeout"` // 超时时间,单位毫秒 Body map[string]interface{} `json:"body"` // 事件的数据 Published bool `json:"published"` // 是否发布了,防止重复发送 }
Event 系统之间的准实时通知事件对象,封装需要发布的事件信息。 需要特别注意的是,每个事件的key必须是全局唯一的,不仅仅是系统内唯一,而是整个系统生态内唯一。 另外,每个时间会被赋予一个超时时间(默认是10s),当事件被发布时会被设置一个发布时间,接收端接收到事件后会根据其系统本地时间和发布时间进行对 比,如果差额超过了超时时间则认为事件超时了则事件监听程序不会被执行,反之事件程序会得到执行。 每个事件允许携带一定量的数据,携带的数据总量以字节长度计算(JSON格式化后的),限制最大数据长度为1k,超过则不允许发送事件。
func NewFCEvent ¶
NewFCEvent 使用事件key构造一个具有默认超时时间的事件对象,默认的超时时间为10s。
func NewFCEventTimeout ¶
NewFCEventTimeout 给定事件的key和超时时间来构建一个事件对象,每个事件都有一个发布时间,如果接收时间的系统时间-发布时间>超时时间则认为事件超时了,则接收端系统不会被触发事件处理程序。
func (*Event) IsOverloaded ¶
IsOverloaded 判断当前事件数据载体的总字节大小是否超标了,以JSON格式化后的字节数为标准,最大只允许1024字节的数据。
func (*Event) SetPubTime ¶
SetPubTime 设置事件的pubTime(发布时间),当事件被发布时由系统自动设置。
type EventListener ¶
type EventListener interface { // EventKeys 该监听器要监听的事件key列表(可指定多个),总是返回非空列表。 EventKeys() []string // OnEvent 事件监听到的回调处理方法,由业务系统自行处理。 OnEvent(event Event) }
EventListener 跨系统的事件监听器接口定义,适用于两个/多个在线系统之间的实时通知,业务系统只需要实现该接口并注册到服务中后即可实现跨系统的事件监听。
type Processor ¶
type Processor interface {
Process(listener ChangedListener)
}
func WatchProcessor ¶
func WatchProcessor(path []string, store backends.StoreClient) Processor