Documentation ¶
Index ¶
- Constants
- Variables
- func Del(id string)
- func Load(folderPath string, opts ...RuleEngineOption) error
- func NewConfig(opts ...types.Option) types.Config
- func Stop()
- type DefaultRuleContext
- func (ctx *DefaultRuleContext) Config() types.Config
- func (ctx *DefaultRuleContext) GetContext() context.Context
- func (ctx *DefaultRuleContext) GetEndFunc() func(msg types.RuleMsg, err error)
- func (ctx *DefaultRuleContext) GetSelfId() string
- func (ctx *DefaultRuleContext) NewMsg(msgType string, metaData types.Metadata, data string) types.RuleMsg
- func (ctx *DefaultRuleContext) SetContext(c context.Context) types.RuleContext
- func (ctx *DefaultRuleContext) SetEndFunc(onEndFunc func(msg types.RuleMsg, err error)) types.RuleContext
- func (ctx *DefaultRuleContext) SubmitTack(task func())
- func (ctx *DefaultRuleContext) TellFailure(msg types.RuleMsg, err error)
- func (ctx *DefaultRuleContext) TellNext(msg types.RuleMsg, relationTypes ...string)
- func (ctx *DefaultRuleContext) TellSelf(msg types.RuleMsg, delayMs int64)
- func (ctx *DefaultRuleContext) TellSuccess(msg types.RuleMsg)
- type JsonParser
- func (p *JsonParser) DecodeRuleChain(config types.Config, dsl []byte) (types.Node, error)
- func (p *JsonParser) DecodeRuleNode(config types.Config, dsl []byte) (types.Node, error)
- func (p *JsonParser) EncodeRuleChain(def interface{}) ([]byte, error)
- func (p *JsonParser) EncodeRuleNode(def interface{}) ([]byte, error)
- type NodeAdditionalInfo
- type NodeConnection
- type PluginComponentRegistry
- type RelationCache
- type RuleChain
- type RuleChainBaseInfo
- type RuleChainConnection
- type RuleChainCtx
- func (rc *RuleChainCtx) AddSubRuleChainCtx(ruleChainId types.RuleNodeId, ctx *RuleChainCtx)
- func (rc *RuleChainCtx) Copy(newCtx *RuleChainCtx)
- func (rc *RuleChainCtx) DSL() []byte
- func (rc *RuleChainCtx) Destroy()
- func (rc *RuleChainCtx) GetFirstNode() (types.NodeCtx, bool)
- func (rc *RuleChainCtx) GetNextNodes(id types.RuleNodeId, relationType string) ([]types.NodeCtx, bool)
- func (rc *RuleChainCtx) GetNodeById(id types.RuleNodeId) (types.NodeCtx, bool)
- func (rc *RuleChainCtx) GetNodeByIndex(index int) (types.NodeCtx, bool)
- func (rc *RuleChainCtx) GetNodeId() types.RuleNodeId
- func (rc *RuleChainCtx) GetNodeRoutes(id types.RuleNodeId) ([]types.RuleNodeRelation, bool)
- func (rc *RuleChainCtx) Init(_ types.Config, configuration types.Configuration) error
- func (rc *RuleChainCtx) IsDebugMode() bool
- func (rc *RuleChainCtx) New() types.Node
- func (rc *RuleChainCtx) OnMsg(ctx types.RuleContext, msg types.RuleMsg) error
- func (rc *RuleChainCtx) ReloadChild(ruleNodeId types.RuleNodeId, def []byte) error
- func (rc *RuleChainCtx) ReloadSelf(def []byte) error
- func (rc *RuleChainCtx) Type() string
- type RuleComponentRegistry
- func (r *RuleComponentRegistry) GetComponents() map[string]types.Node
- func (r *RuleComponentRegistry) NewNode(nodeType string) (types.Node, error)
- func (r *RuleComponentRegistry) Register(node types.Node) error
- func (r *RuleComponentRegistry) RegisterPlugin(name string, file string) error
- func (r *RuleComponentRegistry) Unregister(componentType string) error
- type RuleEngine
- func (e *RuleEngine) DSL() []byte
- func (e *RuleEngine) Initialized() bool
- func (e *RuleEngine) NodeDSL(chainId types.RuleNodeId, childNodeId types.RuleNodeId) []byte
- func (e *RuleEngine) OnMsg(msg types.RuleMsg)
- func (e *RuleEngine) OnMsgWithEndFunc(msg types.RuleMsg, endFunc func(msg types.RuleMsg, err error))
- func (e *RuleEngine) OnMsgWithOptions(msg types.RuleMsg, opts ...types.RuleContextOption)
- func (e *RuleEngine) ReloadChild(chainId types.RuleNodeId, ruleNodeId types.RuleNodeId, dsl []byte) error
- func (e *RuleEngine) ReloadSelf(def []byte, opts ...RuleEngineOption) error
- func (e *RuleEngine) RootRuleChainCtx() *RuleChainCtx
- func (e *RuleEngine) Stop()
- type RuleEngineOption
- type RuleGo
- type RuleMetadata
- type RuleNode
- type RuleNodeCtx
- func (rn *RuleNodeCtx) Copy(newCtx *RuleNodeCtx)
- func (rn *RuleNodeCtx) DSL() []byte
- func (rn *RuleNodeCtx) GetNodeById(_ types.RuleNodeId) (types.NodeCtx, bool)
- func (rn *RuleNodeCtx) GetNodeId() types.RuleNodeId
- func (rn *RuleNodeCtx) IsDebugMode() bool
- func (rn *RuleNodeCtx) ReloadChild(_ types.RuleNodeId, _ []byte) error
- func (rn *RuleNodeCtx) ReloadSelf(def []byte) error
Constants ¶
const PluginsSymbol = "Plugins"
PluginsSymbol 插件检查点 Symbol
Variables ¶
var DefaultRuleGo = &RuleGo{}
var Registry = new(RuleComponentRegistry)
Registry 规则引擎组件默认注册器
Functions ¶
func Load ¶
func Load(folderPath string, opts ...RuleEngineOption) error
Load 加载指定文件夹及其子文件夹所有规则链配置(与.json结尾文件),到规则引擎实例池 规则链ID,使用文件配置的 ruleChain.id
Types ¶
type DefaultRuleContext ¶
type DefaultRuleContext struct {
// contains filtered or unexported fields
}
DefaultRuleContext 默认规则引擎消息处理上下文
func NewRuleContext ¶
func NewRuleContext(config types.Config, ruleChainCtx *RuleChainCtx, from types.NodeCtx, self types.NodeCtx, pool types.Pool, onEnd func(msg types.RuleMsg, err error), context context.Context) *DefaultRuleContext
NewRuleContext 创建一个默认规则引擎消息处理上下文实例
func (*DefaultRuleContext) Config ¶
func (ctx *DefaultRuleContext) Config() types.Config
func (*DefaultRuleContext) GetContext ¶
func (ctx *DefaultRuleContext) GetContext() context.Context
func (*DefaultRuleContext) GetEndFunc ¶
func (ctx *DefaultRuleContext) GetEndFunc() func(msg types.RuleMsg, err error)
func (*DefaultRuleContext) GetSelfId ¶
func (ctx *DefaultRuleContext) GetSelfId() string
func (*DefaultRuleContext) SetContext ¶
func (ctx *DefaultRuleContext) SetContext(c context.Context) types.RuleContext
func (*DefaultRuleContext) SetEndFunc ¶
func (ctx *DefaultRuleContext) SetEndFunc(onEndFunc func(msg types.RuleMsg, err error)) types.RuleContext
func (*DefaultRuleContext) SubmitTack ¶
func (ctx *DefaultRuleContext) SubmitTack(task func())
func (*DefaultRuleContext) TellFailure ¶
func (ctx *DefaultRuleContext) TellFailure(msg types.RuleMsg, err error)
func (*DefaultRuleContext) TellNext ¶
func (ctx *DefaultRuleContext) TellNext(msg types.RuleMsg, relationTypes ...string)
func (*DefaultRuleContext) TellSelf ¶
func (ctx *DefaultRuleContext) TellSelf(msg types.RuleMsg, delayMs int64)
func (*DefaultRuleContext) TellSuccess ¶
func (ctx *DefaultRuleContext) TellSuccess(msg types.RuleMsg)
type JsonParser ¶
type JsonParser struct { }
JsonParser Json
func (*JsonParser) DecodeRuleChain ¶
func (*JsonParser) DecodeRuleNode ¶
func (*JsonParser) EncodeRuleChain ¶
func (p *JsonParser) EncodeRuleChain(def interface{}) ([]byte, error)
func (*JsonParser) EncodeRuleNode ¶
func (p *JsonParser) EncodeRuleNode(def interface{}) ([]byte, error)
type NodeAdditionalInfo ¶
type NodeAdditionalInfo struct { Description string `json:"description"` LayoutX int `json:"layoutX"` LayoutY int `json:"layoutY"` }
NodeAdditionalInfo 用于可视化位置信息(预留字段)
type NodeConnection ¶
type NodeConnection struct { //连接的源节点的id,应该与nodes数组中的某个节点id匹配。 FromId string `json:"fromId"` //连接的目标节点的id,应该与nodes数组中的某个节点id匹配 ToId string `json:"toId"` //连接的类型,决定了什么时候以及如何把消息从一个节点发送到另一个节点。它应该与源节点类型支持的连接类型之一匹配。 //例如,一个JS过滤器节点可能支持两种连接类型:"True"和"False",表示消息是否通过或者失败过滤条件。 Type string `json:"type"` }
NodeConnection 规则链节点连接定义 每个对象代表规则链中两个节点之间的连接
type PluginComponentRegistry ¶
type PluginComponentRegistry struct {
// contains filtered or unexported fields
}
PluginComponentRegistry go plugin组件初始化器
func (*PluginComponentRegistry) Components ¶
func (p *PluginComponentRegistry) Components() []types.Node
func (*PluginComponentRegistry) Init ¶
func (p *PluginComponentRegistry) Init() error
type RelationCache ¶
type RelationCache struct {
// contains filtered or unexported fields
}
type RuleChain ¶
type RuleChain struct { //规则链基础信息定义 RuleChain RuleChainBaseInfo `json:"ruleChain"` //包含了规则链中节点和连接的信息 Metadata RuleMetadata `json:"metadata"` }
RuleChain 规则链定义
func ParserRuleChain ¶
ParserRuleChain 通过json解析规则链结构体
type RuleChainBaseInfo ¶
type RuleChainBaseInfo struct { //规则链ID ID string `json:"id"` //扩展字段 AdditionalInfo map[string]string `json:"additionalInfo"` //Name 规则链的名称 Name string `json:"name"` //表示这个节点是否处于调试模式。如果为真,当节点处理消息时,会触发调试回调函数。 //优先使用子节点的DebugMode配置 DebugMode bool `json:"debugMode"` //Root 表示这个规则链是根规则链还是子规则链。(只做标记使用,非应用在实际逻辑) Root bool `json:"root"` //Configuration 规则链配置信息 Configuration types.Configuration `json:"configuration"` }
RuleChainBaseInfo 规则链基础信息定义
type RuleChainConnection ¶
type RuleChainConnection struct { //连接的源节点的id,应该与nodes数组中的某个节点id匹配。 FromId string `json:"fromId"` //连接的目标子规则链的id,应该与规则引擎中注册的子规则链之一匹配。 ToId string `json:"toId"` //连接的类型,决定了什么时候以及如何把消息从一个节点发送到另一个节点。它应该与源节点类型支持的连接类型之一匹配。 Type string `json:"type"` }
RuleChainConnection 子规则链连接定义 每个对象代表规则链中一个节点和一个子规则链之间的连接
type RuleChainCtx ¶
type RuleChainCtx struct { //节点ID Id types.RuleNodeId //规则链定义 SelfDefinition *RuleChain //规则引擎配置 Config types.Config sync.RWMutex // contains filtered or unexported fields }
RuleChainCtx 规则链实例定义 初始化所有节点 记录规则链,所有节点路由关系
func InitRuleChainCtx ¶
func InitRuleChainCtx(config types.Config, ruleChainDef *RuleChain) (*RuleChainCtx, error)
InitRuleChainCtx 初始化RuleChainCtx
func (*RuleChainCtx) AddSubRuleChainCtx ¶
func (rc *RuleChainCtx) AddSubRuleChainCtx(ruleChainId types.RuleNodeId, ctx *RuleChainCtx)
AddSubRuleChainCtx 添加/更新子规则链 如果存在则先销毁,再覆盖
func (*RuleChainCtx) DSL ¶
func (rc *RuleChainCtx) DSL() []byte
func (*RuleChainCtx) Destroy ¶
func (rc *RuleChainCtx) Destroy()
func (*RuleChainCtx) GetFirstNode ¶
func (rc *RuleChainCtx) GetFirstNode() (types.NodeCtx, bool)
GetFirstNode 获取第一个节点,消息从该节点开始流转。默认是index=0的节点
func (*RuleChainCtx) GetNextNodes ¶
func (rc *RuleChainCtx) GetNextNodes(id types.RuleNodeId, relationType string) ([]types.NodeCtx, bool)
GetNextNodes 获取当前节点指定关系的子节点
func (*RuleChainCtx) GetNodeById ¶
func (rc *RuleChainCtx) GetNodeById(id types.RuleNodeId) (types.NodeCtx, bool)
func (*RuleChainCtx) GetNodeByIndex ¶
func (rc *RuleChainCtx) GetNodeByIndex(index int) (types.NodeCtx, bool)
func (*RuleChainCtx) GetNodeId ¶
func (rc *RuleChainCtx) GetNodeId() types.RuleNodeId
func (*RuleChainCtx) GetNodeRoutes ¶
func (rc *RuleChainCtx) GetNodeRoutes(id types.RuleNodeId) ([]types.RuleNodeRelation, bool)
func (*RuleChainCtx) Init ¶
func (rc *RuleChainCtx) Init(_ types.Config, configuration types.Configuration) error
Init 初始化
func (*RuleChainCtx) IsDebugMode ¶
func (rc *RuleChainCtx) IsDebugMode() bool
func (*RuleChainCtx) New ¶
func (rc *RuleChainCtx) New() types.Node
func (*RuleChainCtx) OnMsg ¶
func (rc *RuleChainCtx) OnMsg(ctx types.RuleContext, msg types.RuleMsg) error
OnMsg 处理消息
func (*RuleChainCtx) ReloadChild ¶
func (rc *RuleChainCtx) ReloadChild(ruleNodeId types.RuleNodeId, def []byte) error
func (*RuleChainCtx) ReloadSelf ¶
func (rc *RuleChainCtx) ReloadSelf(def []byte) error
type RuleComponentRegistry ¶
RuleComponentRegistry 组件注册器
func (*RuleComponentRegistry) GetComponents ¶
func (r *RuleComponentRegistry) GetComponents() map[string]types.Node
func (*RuleComponentRegistry) NewNode ¶
func (r *RuleComponentRegistry) NewNode(nodeType string) (types.Node, error)
NewNode 获取规则引擎节点组件
func (*RuleComponentRegistry) Register ¶
func (r *RuleComponentRegistry) Register(node types.Node) error
Register 注册规则引擎节点组件
func (*RuleComponentRegistry) RegisterPlugin ¶
func (r *RuleComponentRegistry) RegisterPlugin(name string, file string) error
RegisterPlugin 注册规则引擎节点组件
func (*RuleComponentRegistry) Unregister ¶
func (r *RuleComponentRegistry) Unregister(componentType string) error
type RuleEngine ¶
type RuleEngine struct { //规则引擎实例标识 Id string //配置 Config types.Config // contains filtered or unexported fields }
RuleEngine 规则引擎 每个规则引擎实例只有一个根规则链,如果没设置规则链则无法处理数据
func New ¶
func New(id string, rootRuleChainSrc []byte, opts ...RuleEngineOption) (*RuleEngine, error)
New 创建一个新的RuleEngine并将其存储在RuleGo规则链池中
func (*RuleEngine) DSL ¶
func (e *RuleEngine) DSL() []byte
func (*RuleEngine) Initialized ¶
func (e *RuleEngine) Initialized() bool
func (*RuleEngine) NodeDSL ¶
func (e *RuleEngine) NodeDSL(chainId types.RuleNodeId, childNodeId types.RuleNodeId) []byte
func (*RuleEngine) OnMsg ¶
func (e *RuleEngine) OnMsg(msg types.RuleMsg)
OnMsg 把消息交给规则引擎处理,异步执行 根据规则链节点配置和连接关系处理消息
func (*RuleEngine) OnMsgWithEndFunc ¶
func (e *RuleEngine) OnMsgWithEndFunc(msg types.RuleMsg, endFunc func(msg types.RuleMsg, err error))
OnMsgWithEndFunc 把消息交给规则引擎处理,异步执行 endFunc 用于数据经过规则链执行完的回调,用于获取规则链处理结果数据。注意:如果规则链有多个结束点,回调函数则会执行多次
func (*RuleEngine) OnMsgWithOptions ¶
func (e *RuleEngine) OnMsgWithOptions(msg types.RuleMsg, opts ...types.RuleContextOption)
OnMsgWithOptions 把消息交给规则引擎处理,异步执行 可以携带context选项和结束回调选项 context 用于不同组件实例数据共享 endFunc 用于数据经过规则链执行完的回调,用于获取规则链处理结果数据。注意:如果规则链有多个结束点,回调函数则会执行多次
func (*RuleEngine) ReloadChild ¶
func (e *RuleEngine) ReloadChild(chainId types.RuleNodeId, ruleNodeId types.RuleNodeId, dsl []byte) error
ReloadChild 更新节点,包括根规则链下子节点、子规则链、子规则链下的子节点 子规则链不存则添加否则更新,子节点不存在更新不成功 如果chainId和ruleNodeId为空更新根规则链 chainId 子规则链,如果空,则表示更新根规则链 ruleNodeId 要更新的子节点或者子规则链 dsl 子节点/子规则链配置
func (*RuleEngine) ReloadSelf ¶
func (e *RuleEngine) ReloadSelf(def []byte, opts ...RuleEngineOption) error
ReloadSelf 重新加载规则链
func (*RuleEngine) RootRuleChainCtx ¶
func (e *RuleEngine) RootRuleChainCtx() *RuleChainCtx
RootRuleChainCtx 获取根规则链
func (*RuleEngine) Stop ¶
func (e *RuleEngine) Stop()
type RuleEngineOption ¶
type RuleEngineOption func(*RuleEngine) error
RuleEngineOption is a function type that modifies the RuleEngine.
func WithAddSubChain ¶
func WithAddSubChain(subChainId string, subChain []byte) RuleEngineOption
WithAddSubChain 添加子规则链选项
func WithConfig ¶
func WithConfig(config types.Config) RuleEngineOption
WithConfig is an option that sets the Config of the RuleEngine.
type RuleGo ¶
type RuleGo struct {
// contains filtered or unexported fields
}
RuleGo 规则引擎实例池
func (*RuleGo) Load ¶
func (g *RuleGo) Load(folderPath string, opts ...RuleEngineOption) error
Load 加载指定文件夹及其子文件夹所有规则链配置(与.json结尾文件),到规则引擎实例池 规则链ID,使用规则链文件配置的ruleChain.id
func (*RuleGo) New ¶
func (g *RuleGo) New(id string, rootRuleChainSrc []byte, opts ...RuleEngineOption) (*RuleEngine, error)
New 创建一个新的RuleEngine并将其存储在RuleGo规则链池中 如果指定id="",则使用规则链文件的ruleChain.id
type RuleMetadata ¶
type RuleMetadata struct { //数据流转的第一个节点,默认:0 FirstNodeIndex int `json:"firstNodeIndex"` //节点组件定义 //每个对象代表规则链中的一个规则节点 Nodes []*RuleNode `json:"nodes"` //连接定义 //每个对象代表规则链中两个节点之间的连接 Connections []NodeConnection `json:"connections"` //子规则链链接 //每个对象代表规则链中一个节点和一个子规则链之间的连接 RuleChainConnections []RuleChainConnection `json:"ruleChainConnections"` }
RuleMetadata 规则链元数据定义,包含了规则链中节点和连接的信息
type RuleNode ¶
type RuleNode struct { //节点的唯一标识符,可以是任意字符串 Id string `json:"Id"` //扩展字段 AdditionalInfo NodeAdditionalInfo `json:"additionalInfo"` //节点的类型,决定了节点的逻辑和行为。它应该与规则引擎中注册的节点类型之一匹配。 Type string `json:"type"` //节点的名称,可以是任意字符串 Name string `json:"name"` //表示这个节点是否处于调试模式。如果为真,当节点处理消息时,会触发调试回调函数。 DebugMode bool `json:"debugMode"` //包含了节点的配置参数,具体内容取决于节点类型。 //例如,一个JS过滤器节点可能有一个`jsScript`字段,定义了过滤逻辑, //而一个REST API调用节点可能有一个`restEndpointUrlPattern`字段,定义了要调用的URL。 Configuration types.Configuration `json:"configuration"` }
RuleNode 规则链节点信息定义
func ParserRuleNode ¶
ParserRuleNode 通过json解析节点结构体
type RuleNodeCtx ¶
type RuleNodeCtx struct { //组件实例 types.Node //组件配置 SelfDefinition *RuleNode //规则引擎配置 Config types.Config }
RuleNodeCtx 节点组件实例定义
func InitRuleNodeCtx ¶
func InitRuleNodeCtx(config types.Config, selfDefinition *RuleNode) (*RuleNodeCtx, error)
InitRuleNodeCtx 初始化RuleNodeCtx
func (*RuleNodeCtx) DSL ¶
func (rn *RuleNodeCtx) DSL() []byte
func (*RuleNodeCtx) GetNodeById ¶
func (rn *RuleNodeCtx) GetNodeById(_ types.RuleNodeId) (types.NodeCtx, bool)
func (*RuleNodeCtx) GetNodeId ¶
func (rn *RuleNodeCtx) GetNodeId() types.RuleNodeId
func (*RuleNodeCtx) IsDebugMode ¶
func (rn *RuleNodeCtx) IsDebugMode() bool
func (*RuleNodeCtx) ReloadChild ¶
func (rn *RuleNodeCtx) ReloadChild(_ types.RuleNodeId, _ []byte) error
func (*RuleNodeCtx) ReloadSelf ¶
func (rn *RuleNodeCtx) ReloadSelf(def []byte) error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
api
|
|
components
|
|
examples
|
|
Package pool Note: This file is inspired by: Valyala, A. (2023) workerpool.go (Version 1.48.0) [Source code].
|
Package pool Note: This file is inspired by: Valyala, A. (2023) workerpool.go (Version 1.48.0) [Source code]. |
testcases
|
|
utils
|
|