functions
functions
component: execute custom processing functions. Used for lightweight custom node implementation, allowing your Golang custom functions to become components in seconds. Supports getting the function name value from metadata dynamically using ${metadataKey}.
Before using this component, you must register custom processing functions using the following method, and the default framework does not provide any processing functions.
action.Functions.Register(functionName string, f func(ctx types.RuleContext, msg types.RuleMsg))
1
If the function processing is successful, you must use the following method to notify the rule engine that it has been successfully processed:
//TellSuccess notifies the rule engine that the current message processing is successful and sends the message to the next node through the `Success` relationship
ctx.TellSuccess(msg RuleMsg)
//TellNext sends the message to the next node using the specified relationTypes
ctx.TellNext(msg RuleMsg, relationTypes ...string)
1
2
3
4
2
3
4
If the function processing fails, the implementation must call the tellFailure method:
//TellFailure notifies the rule engine that the current message processing failed and sends the message to the next node through the `Failure` relationship
ctx.TellFailure(msg RuleMsg, err error)
1
2
2
- ctx: context
- msg: the message passed in by the previous node
# Configuration
Field | Type | Description | Default value |
---|---|---|---|
functionName | string | The name of the function to call, can using Component Configuration Variables | None |
# Relation Type
Function custom
# Execution result
Function custom
# Configuration example
{
"id": "s1",
"type": "functions",
"name": "Call function 1",
"configuration": {
"functionName": "handleMsg"
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Application example
Example reference: Example (opens new window)
# Difference between config.Udf and functions custom functions
- config.Udf : custom functions called by js script at runtime, functions have no fixed parameters and return values.
- functions : custom functions called by the
functions
node through the configuration function name, functions must be of this type:func(ctx types.RuleContext, msg types.RuleMsg)
.
Edit this page on GitHub (opens new window)
Last Updated: 2024/10/23, 10:13:01