Options
# RuleContextOption
Configuration items for the execution of a rule engine instance. Usage: ruleEngine.OnMsg(msg, ...RuleContextOption)
, example:
ruleEngine.OnMsg(msg, types.WithOnEnd(func(ctx types.RuleContext, msg types.RuleMsg, err error) {
// do something
}), types.WWithOnRuleChainCompleted(func(ctx RuleContext, snapshot RuleChainRunSnapshot){
// do something
}))
2
3
4
5
The following options are available:
# WithOnEnd
Callback for when a rule chain branch execution ends. If the rule chain has multiple endpoints, the callback function will be executed multiple times
types.WithOnEnd(func(ctx types.RuleContext, msg types.RuleMsg, err error) {
}
2
3
# WithContext
Context
- Used for sharing data or semaphores between different component instances
- Used for timeout cancellation
types.WithContext(c context.Context)
# WithOnAllNodeCompleted
Callback function when all branches of the rule chain have completed execution.
- Called only once
types.WithOnAllNodeCompleted(func(){
})
2
3
# WithOnRuleChainCompleted
Callback function when the rule chain execution is completed, and collects the runtime logs of each node.
types.WithOnRuleChainCompleted(func(ctx RuleContext, snapshot RuleChainRunSnapshot){
})
2
3
- RuleChainRunSnapshot:
Field | Type | Description | Default Value |
---|---|---|---|
RuleChain | RuleChain | Rule chain snapshot: Reference | None |
id | string | Message ID | None |
startTs | int64 | Rule chain start execution time | None |
endTs | int64 | Rule chain end execution time | None |
logs | []RuleNodeRunLog | Execution log of each node | None |
additionalInfo | object | Additional information | None |
- RuleNodeRunLog:
Field | Type | Description | Default Value |
---|---|---|---|
nodeId | string | Node ID | None |
inMsg | RuleMsg | Input message: Reference | None |
outMsg | RuleMsg | Output message: Reference | None |
relationType | string | Connection type with the next node | None |
err | string | Error information | None |
logItems | []string | Other logs during execution | None |
startTs | int64 | Rule chain start execution time | None |
endTs | int64 | Rule chain end execution time | None |
# WithOnNodeCompleted
Callback function when a node is completed, and collects the node's runtime log.
types.WithOnNodeCompleted(func(ctx RuleContext, nodeRunLog RuleNodeRunLog){
})
2
3
# WithOnNodeDebug
Node debug log callback function.
Same as config.OnDebug
. It is called in real-time asynchronously and will only trigger if the node or rule chain is configured with debugMode
enabled
types.WithOnNodeDebug(func(ruleChainId string, flowType string, nodeId string, msg RuleMsg, relationType string, err error)){
})
2
3
TIP
WithOnNodeDebug
callback function contains custom logic that is triggered asynchronously, and the execution order cannot be guaranteed. It may be executed after WithOnAllNodeCompleted
and WithOnRuleChainCompleted
.
# WithStartNode
Set the first start execution node of the rule chain.
types.WithStartNode(nodeId string)
# WithTellNext
Set to search for the next or multiple execution nodes by specifying the node ID. Used to restore the execution link of the rule chain.
types.WithTellNext(fromNodeId string, relationTypes ...string)