Documentation ¶
Overview ¶
Package rulego provides a lightweight, high-performance, embedded, orchestrable component-based rule engine.
Usage ¶
Implement your business requirements by configuring components in the rule chain, and support dynamic modification. Rule chain definition format:
{ "ruleChain": { "id":"rule01" }, "metadata": { "nodes": [ ], "connections": [ ] } }
nodes:configure components. You can use built-in components and third-party extension components without writing any code.
connections:configure the relation type between components. Determine the data flow.
Example:
var ruleFile = ` { "ruleChain": { "id":"rule02", "name": "test", "root": true }, "metadata": { "nodes": [ { "id": "s1", "type": "jsTransform", "name": "transform", "debugMode": true, "configuration": { "jsScript": "metadata['state']='modify by js';\n msg['addField']='addValueFromJs'; return {'msg':msg,'metadata':metadata,'msgType':msgType};" } }, { "id": "s2", "type": "restApiCall", "name": "push data", "debugMode": true, "configuration": { "restEndpointUrlPattern": "http://127.0.0.1:9090/api/msg", "requestMethod": "POST", } } ], "connections": [ { "fromId": "s1", "toId": "s2", "type": "Success" } ] } } `
Create Rule Engine Instance
ruleEngine, err := rulego.New("rule01", []byte(ruleFile))
Define Message Metadata
metaData := types.NewMetadata() metaData.PutValue("productType", "test01")
Define Message Payload And Type
msg := types.NewMsg(0, "TELEMETRY_MSG", types.JSON, metaData, "{\"temperature\":35}")
Processing Message
ruleEngine.OnMsg(msg)
Update Rule Chain
err := ruleEngine.ReloadSelf([]byte(ruleFile))
Load All Rule Chain
err := ruleEngine.Load("./rulechains")
Get Engine Instance
ruleEngine, ok := rulego.Get("rule01")
Index ¶
- Constants
- Variables
- func Del(id string)
- func Load(folderPath string, opts ...RuleEngineOption) error
- func NewConfig(opts ...types.Option) types.Config
- func OnMsg(msg types.RuleMsg)
- func ParserRuleChain(rootRuleChain []byte) (types.RuleChain, error)
- func ParserRuleNode(rootRuleChain []byte) (types.RuleNode, error)
- func Range(f func(key, value any) bool)
- func Reload(opts ...RuleEngineOption)
- func Stop()
- type DefaultRuleContext
- func (ctx *DefaultRuleContext) Config() types.Config
- func (ctx *DefaultRuleContext) DoOnEnd(msg types.RuleMsg, err error, relationType string)
- func (ctx *DefaultRuleContext) ExecuteNode(chanCtx context.Context, nodeId string, msg types.RuleMsg, skipTellNext bool, ...)
- func (ctx *DefaultRuleContext) From() types.NodeCtx
- func (ctx *DefaultRuleContext) GetCallbackFunc(functionName string) interface{}
- func (ctx *DefaultRuleContext) GetContext() context.Context
- func (ctx *DefaultRuleContext) GetEndFunc() types.OnEndFunc
- func (ctx *DefaultRuleContext) GetRuleChainPool() *RuleGo
- func (ctx *DefaultRuleContext) GetSelfId() string
- func (ctx *DefaultRuleContext) IsDebugMode() bool
- func (ctx *DefaultRuleContext) NewMsg(msgType string, metaData types.Metadata, data string) types.RuleMsg
- func (ctx *DefaultRuleContext) NewNextNodeRuleContext(nextNode types.NodeCtx) *DefaultRuleContext
- func (ctx *DefaultRuleContext) OnDebug(ruleChainId string, flowType string, nodeId string, msg types.RuleMsg, ...)
- func (ctx *DefaultRuleContext) RuleChain() types.NodeCtx
- func (ctx *DefaultRuleContext) Self() types.NodeCtx
- func (ctx *DefaultRuleContext) SetAllCompletedFunc(f func()) types.RuleContext
- func (ctx *DefaultRuleContext) SetCallbackFunc(functionName string, f interface{})
- func (ctx *DefaultRuleContext) SetContext(c context.Context) types.RuleContext
- func (ctx *DefaultRuleContext) SetEndFunc(onEndFunc types.OnEndFunc) types.RuleContext
- func (ctx *DefaultRuleContext) SetOnAllNodeCompleted(onAllNodeCompleted func())
- func (ctx *DefaultRuleContext) SetRuleChainPool(ruleChainPool *RuleGo)
- func (ctx *DefaultRuleContext) SubmitTack(task func())
- func (ctx *DefaultRuleContext) TellFailure(msg types.RuleMsg, err error)
- func (ctx *DefaultRuleContext) TellFlow(msg types.RuleMsg, chainId string, onEndFunc types.OnEndFunc, ...)
- 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, chainCtx types.Node) (types.Node, error)
- func (p *JsonParser) EncodeRuleChain(def interface{}) ([]byte, error)
- func (p *JsonParser) EncodeRuleNode(def interface{}) ([]byte, error)
- type PluginComponentRegistry
- type RelationCache
- type 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) GetRuleChainPool() *RuleGo
- 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)
- func (rc *RuleChainCtx) ReloadChild(ruleNodeId types.RuleNodeId, def []byte) error
- func (rc *RuleChainCtx) ReloadSelf(def []byte) error
- func (rc *RuleChainCtx) SetRuleChainPool(ruleChainPool *RuleGo)
- func (rc *RuleChainCtx) Type() string
- type RuleComponentRegistry
- func (r *RuleComponentRegistry) GetComponentForms() types.ComponentFormList
- 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) Definition() types.RuleChain
- func (e *RuleEngine) Initialized() bool
- func (e *RuleEngine) NodeDSL(chainId types.RuleNodeId, childNodeId types.RuleNodeId) []byte
- func (e *RuleEngine) OnMsg(msg types.RuleMsg, opts ...types.RuleContextOption)
- func (e *RuleEngine) OnMsgAndWait(msg types.RuleMsg, opts ...types.RuleContextOption)
- func (e *RuleEngine) OnMsgWithEndFunc(msg types.RuleMsg, endFunc types.OnEndFunc)
- func (e *RuleEngine) OnMsgWithOptions(msg types.RuleMsg, opts ...types.RuleContextOption)
- func (e *RuleEngine) Reload(opts ...RuleEngineOption) error
- func (e *RuleEngine) ReloadChild(ruleNodeId string, 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
- func (g *RuleGo) Del(id string)
- func (g *RuleGo) Get(id string) (*RuleEngine, bool)
- func (g *RuleGo) Load(folderPath string, opts ...RuleEngineOption) error
- func (g *RuleGo) New(id string, rootRuleChainSrc []byte, opts ...RuleEngineOption) (*RuleEngine, error)
- func (g *RuleGo) OnMsg(msg types.RuleMsg)
- func (g *RuleGo) Range(f func(key, value any) bool)
- func (g *RuleGo) Stop()
- 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
- type RunSnapshot
Constants ¶
const PluginsSymbol = "Plugins"
PluginsSymbol 插件检查点 Symbol
Variables ¶
var DefaultRuleGo = &RuleGo{}
var Registry = new(RuleComponentRegistry)
Registry 规则引擎组件默认注册器
Functions ¶
func Load ¶ added in v0.14.0
func Load(folderPath string, opts ...RuleEngineOption) error
Load 加载指定文件夹及其子文件夹所有规则链配置(与.json结尾文件),到规则引擎实例池 规则链ID,使用文件配置的 ruleChain.id
func ParserRuleChain ¶
ParserRuleChain 通过json解析规则链结构体
func ParserRuleNode ¶
ParserRuleNode 通过json解析节点结构体
Types ¶
type DefaultRuleContext ¶
type DefaultRuleContext struct {
// contains filtered or unexported fields
}
DefaultRuleContext 默认规则引擎消息处理上下文
func NewRuleContext ¶
func NewRuleContext(context context.Context, config types.Config, ruleChainCtx *RuleChainCtx, from types.NodeCtx, self types.NodeCtx, pool types.Pool, onEnd types.OnEndFunc, ruleChainPool *RuleGo) *DefaultRuleContext
NewRuleContext 创建一个默认规则引擎消息处理上下文实例
func (*DefaultRuleContext) Config ¶
func (ctx *DefaultRuleContext) Config() types.Config
func (*DefaultRuleContext) DoOnEnd ¶ added in v0.18.0
func (ctx *DefaultRuleContext) DoOnEnd(msg types.RuleMsg, err error, relationType string)
DoOnEnd 结束规则链分支执行,触发 OnEnd 回调函数
func (*DefaultRuleContext) ExecuteNode ¶ added in v0.17.0
func (ctx *DefaultRuleContext) ExecuteNode(chanCtx context.Context, nodeId string, msg types.RuleMsg, skipTellNext bool, onEnd types.OnEndFunc)
ExecuteNode 从指定节点开始执行,如果 skipTellNext=true 则只执行当前节点,不通知下一个节点。 onEnd 查看获得最终执行结果
func (*DefaultRuleContext) From ¶ added in v0.18.0
func (ctx *DefaultRuleContext) From() types.NodeCtx
func (*DefaultRuleContext) GetCallbackFunc ¶ added in v0.20.0
func (ctx *DefaultRuleContext) GetCallbackFunc(functionName string) interface{}
func (*DefaultRuleContext) GetContext ¶ added in v0.13.0
func (ctx *DefaultRuleContext) GetContext() context.Context
func (*DefaultRuleContext) GetEndFunc ¶
func (ctx *DefaultRuleContext) GetEndFunc() types.OnEndFunc
func (*DefaultRuleContext) GetRuleChainPool ¶ added in v0.17.0
func (ctx *DefaultRuleContext) GetRuleChainPool() *RuleGo
GetRuleChainPool 获取子规则链池
func (*DefaultRuleContext) GetSelfId ¶
func (ctx *DefaultRuleContext) GetSelfId() string
func (*DefaultRuleContext) IsDebugMode ¶ added in v0.20.0
func (ctx *DefaultRuleContext) IsDebugMode() bool
IsDebugMode 是否调试模式,优先使用规则链指定的调试模式
func (*DefaultRuleContext) NewNextNodeRuleContext ¶ added in v0.15.0
func (ctx *DefaultRuleContext) NewNextNodeRuleContext(nextNode types.NodeCtx) *DefaultRuleContext
NewNextNodeRuleContext 创建下一个节点的规则引擎消息处理上下文实例RuleContext
func (*DefaultRuleContext) RuleChain ¶ added in v0.18.0
func (ctx *DefaultRuleContext) RuleChain() types.NodeCtx
func (*DefaultRuleContext) Self ¶ added in v0.18.0
func (ctx *DefaultRuleContext) Self() types.NodeCtx
func (*DefaultRuleContext) SetAllCompletedFunc ¶ added in v0.15.0
func (ctx *DefaultRuleContext) SetAllCompletedFunc(f func()) types.RuleContext
func (*DefaultRuleContext) SetCallbackFunc ¶ added in v0.20.0
func (ctx *DefaultRuleContext) SetCallbackFunc(functionName string, f interface{})
func (*DefaultRuleContext) SetContext ¶ added in v0.13.0
func (ctx *DefaultRuleContext) SetContext(c context.Context) types.RuleContext
func (*DefaultRuleContext) SetEndFunc ¶
func (ctx *DefaultRuleContext) SetEndFunc(onEndFunc types.OnEndFunc) types.RuleContext
func (*DefaultRuleContext) SetOnAllNodeCompleted ¶ added in v0.17.0
func (ctx *DefaultRuleContext) SetOnAllNodeCompleted(onAllNodeCompleted func())
SetOnAllNodeCompleted 设置所有节点执行完回调
func (*DefaultRuleContext) SetRuleChainPool ¶ added in v0.17.0
func (ctx *DefaultRuleContext) SetRuleChainPool(ruleChainPool *RuleGo)
SetRuleChainPool 设置子规则链池
func (*DefaultRuleContext) SubmitTack ¶
func (ctx *DefaultRuleContext) SubmitTack(task func())
func (*DefaultRuleContext) TellFailure ¶
func (ctx *DefaultRuleContext) TellFailure(msg types.RuleMsg, err error)
func (*DefaultRuleContext) TellFlow ¶ added in v0.17.0
func (ctx *DefaultRuleContext) TellFlow(msg types.RuleMsg, chainId string, onEndFunc types.OnEndFunc, onAllNodeCompleted func())
TellFlow 执行子规则链,ruleChainId 规则链ID onEndFunc 子规则链链分支执行完的回调,并返回该链执行结果,如果同时触发多个分支链,则会调用多次 onAllNodeCompleted 所以节点执行完之后的回调,无结果返回 如果找不到规则链,并把消息通过`Failure`关系发送到下一个节点
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 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 RuleChainCtx ¶
type RuleChainCtx struct { //节点ID Id types.RuleNodeId //规则链定义 SelfDefinition *types.RuleChain //规则引擎配置 Config types.Config sync.RWMutex // contains filtered or unexported fields }
RuleChainCtx 规则链实例定义 初始化所有节点 记录规则链,所有节点路由关系
func InitRuleChainCtx ¶
InitRuleChainCtx 初始化RuleChainCtx
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) GetRuleChainPool ¶ added in v0.15.0
func (rc *RuleChainCtx) GetRuleChainPool() *RuleGo
GetRuleChainPool 获取子规则链池
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)
OnMsg 处理消息
func (*RuleChainCtx) ReloadChild ¶
func (rc *RuleChainCtx) ReloadChild(ruleNodeId types.RuleNodeId, def []byte) error
func (*RuleChainCtx) ReloadSelf ¶
func (rc *RuleChainCtx) ReloadSelf(def []byte) error
func (*RuleChainCtx) SetRuleChainPool ¶ added in v0.15.0
func (rc *RuleChainCtx) SetRuleChainPool(ruleChainPool *RuleGo)
SetRuleChainPool 设置子规则链池
type RuleComponentRegistry ¶
RuleComponentRegistry 组件注册器
func (*RuleComponentRegistry) GetComponentForms ¶ added in v0.15.0
func (r *RuleComponentRegistry) GetComponentForms() types.ComponentFormList
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 //子规则链池 RuleChainPool *RuleGo // contains filtered or unexported fields }
RuleEngine 规则引擎 每个规则引擎实例只有一个根规则链,如果没设置规则链则无法处理数据
func New ¶
func New(id string, rootRuleChainSrc []byte, opts ...RuleEngineOption) (*RuleEngine, error)
New 创建一个新的RuleEngine并将其存储在RuleGo规则链池中
func (*RuleEngine) Definition ¶ added in v0.20.0
func (e *RuleEngine) Definition() types.RuleChain
func (*RuleEngine) Initialized ¶
func (e *RuleEngine) Initialized() bool
func (*RuleEngine) NodeDSL ¶
func (e *RuleEngine) NodeDSL(chainId types.RuleNodeId, childNodeId types.RuleNodeId) []byte
NodeDSL 获取规则链节点配置
func (*RuleEngine) OnMsg ¶
func (e *RuleEngine) OnMsg(msg types.RuleMsg, opts ...types.RuleContextOption)
OnMsg 把消息交给规则引擎处理,异步执行 提供可选参数types.RuleContextOption
func (*RuleEngine) OnMsgAndWait ¶ added in v0.15.0
func (e *RuleEngine) OnMsgAndWait(msg types.RuleMsg, opts ...types.RuleContextOption)
OnMsgAndWait 把消息交给规则引擎处理,同步执行 等规则链所有节点执行完后返回
func (*RuleEngine) OnMsgWithEndFunc ¶
func (e *RuleEngine) OnMsgWithEndFunc(msg types.RuleMsg, endFunc types.OnEndFunc)
OnMsgWithEndFunc 把消息交给规则引擎处理,异步执行 endFunc 用于数据经过规则链执行完的回调,用于获取规则链处理结果数据。注意:如果规则链有多个结束点,回调函数则会执行多次 Deprecated 使用OnMsg代替
func (*RuleEngine) OnMsgWithOptions ¶ added in v0.13.0
func (e *RuleEngine) OnMsgWithOptions(msg types.RuleMsg, opts ...types.RuleContextOption)
OnMsgWithOptions 把消息交给规则引擎处理,异步执行 可以携带context选项和结束回调选项 context 用于不同组件实例数据共享 endFunc 用于数据经过规则链执行完的回调,用于获取规则链处理结果数据。注意:如果规则链有多个结束点,回调函数则会执行多次 Deprecated 使用OnMsg代替
func (*RuleEngine) Reload ¶ added in v0.20.0
func (e *RuleEngine) Reload(opts ...RuleEngineOption) error
func (*RuleEngine) ReloadChild ¶
func (e *RuleEngine) ReloadChild(ruleNodeId string, dsl []byte) error
ReloadChild 更新根规则链或者其下某个节点 如果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 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 ¶ added in v0.14.0
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 RuleNodeCtx ¶
type RuleNodeCtx struct { //组件实例 types.Node //规则链配置上下文 ChainCtx *RuleChainCtx //组件配置 SelfDefinition *types.RuleNode //规则引擎配置 Config types.Config }
RuleNodeCtx 节点组件实例定义
func InitRuleNodeCtx ¶
func InitRuleNodeCtx(config types.Config, chainCtx *RuleChainCtx, selfDefinition *types.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
type RunSnapshot ¶ added in v0.20.0
type RunSnapshot struct {
// contains filtered or unexported fields
}
func NewRunSnapshot ¶ added in v0.20.0
func NewRunSnapshot(msgId string, chainCtx *RuleChainCtx, startTs int64) *RunSnapshot
Directories ¶
Path | Synopsis |
---|---|
api
|
|
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]. |
utils
|
|