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 ¶
- Variables
- func Del(id string)
- func Get(id string) (types.RuleEngine, bool)
- func Load(folderPath string, opts ...types.RuleEngineOption) error
- func New(id string, rootRuleChainSrc []byte, opts ...types.RuleEngineOption) (types.RuleEngine, error)
- func NewConfig(opts ...types.Option) types.Config
- func OnMsg(msg types.RuleMsg)
- func Range(f func(key, value any) bool)
- func Reload(opts ...types.RuleEngineOption)
- func Stop()
- func WithConfig(config types.Config) types.RuleEngineOption
- type RuleGo
- func (g *RuleGo) Del(id string)
- func (g *RuleGo) Get(id string) (types.RuleEngine, bool)
- func (g *RuleGo) Load(folderPath string, opts ...types.RuleEngineOption) error
- func (g *RuleGo) New(id string, rootRuleChainSrc []byte, opts ...types.RuleEngineOption) (types.RuleEngine, error)
- func (g *RuleGo) OnMsg(msg types.RuleMsg)
- func (g *RuleGo) Pool() *engine.Pool
- func (g *RuleGo) Range(f func(key, value any) bool)
- func (g *RuleGo) Reload(opts ...types.RuleEngineOption)
- func (g *RuleGo) SetCallbacks(callbacks types.Callbacks)
- func (g *RuleGo) Stop()
Constants ¶
This section is empty.
Variables ¶
var Endpoints = endpoint.DefaultPool
var Registry = engine.Registry
Registry is the default registrar for rule engine components.
var Rules = &RuleGo{pool: engine.DefaultPool}
Rules is the default instance of RuleGo with the rule engine pool set to the default pool.
Functions ¶
func Get ¶
func Get(id string) (types.RuleEngine, bool)
Get retrieves a rule engine instance by its ID.
func Load ¶ added in v0.14.0
func Load(folderPath string, opts ...types.RuleEngineOption) error
Load loads all rule chain configurations from the specified folder and its subFolders into the rule engine instance pool. The rule chain ID is taken from the ruleChain.id specified in the rule chain file.
func New ¶
func New(id string, rootRuleChainSrc []byte, opts ...types.RuleEngineOption) (types.RuleEngine, error)
New creates a new RuleEngine and stores it in the RuleGo rule chain pool.
func OnMsg ¶ added in v0.15.0
OnMsg calls all rule engine instances to process a message. All rule chains in the rule engine instance pool will attempt to process the message.
func Reload ¶ added in v0.20.0
func Reload(opts ...types.RuleEngineOption)
Reload reloads all rule engine instances.
func WithConfig ¶
func WithConfig(config types.Config) types.RuleEngineOption
WithConfig is an option that sets the Config of the RuleEngine.
Types ¶
type RuleGo ¶
type RuleGo struct {
// contains filtered or unexported fields
}
RuleGo is a pool of rule engine instances.
func (*RuleGo) Get ¶
func (g *RuleGo) Get(id string) (types.RuleEngine, bool)
Get retrieves a rule engine instance by its ID.
func (*RuleGo) Load ¶ added in v0.14.0
func (g *RuleGo) Load(folderPath string, opts ...types.RuleEngineOption) error
Load loads all rule chain configurations from the specified folder and its subFolders into the rule engine instance pool. The rule chain ID is taken from the ruleChain.id specified in the rule chain file.
func (*RuleGo) New ¶
func (g *RuleGo) New(id string, rootRuleChainSrc []byte, opts ...types.RuleEngineOption) (types.RuleEngine, error)
New creates a new RuleEngine and stores it in the RuleGo rule chain pool. If the specified id is empty (""), the ruleChain.id from the rule chain file is used.
func (*RuleGo) OnMsg ¶ added in v0.15.0
OnMsg calls all rule engine instances to process a message. All rule chains in the rule engine instance pool will attempt to process the message.
func (*RuleGo) Reload ¶ added in v0.21.0
func (g *RuleGo) Reload(opts ...types.RuleEngineOption)
Reload reloads all rule engine instances.
func (*RuleGo) SetCallbacks ¶ added in v0.30.0
SetCallbacks sets the callbacks for the rule engine pool.
Directories
¶
| Path | Synopsis |
|---|---|
|
api
|
|
|
types
Package types defines the core interfaces, data structures, and contracts for the RuleGo rule engine framework.
|
Package types defines the core interfaces, data structures, and contracts for the RuleGo rule engine framework. |
|
types/endpoint
Package endpoint provides the core definitions and interfaces for endpoints in the RuleGo framework.
|
Package endpoint provides the core definitions and interfaces for endpoints in the RuleGo framework. |
|
builtin
|
|
|
aspect
Package aspect provides built-in aspect-oriented programming (AOP) functionality for the RuleGo rule engine.
|
Package aspect provides built-in aspect-oriented programming (AOP) functionality for the RuleGo rule engine. |
|
funcs
Package funcs provides built-in function implementations for the RuleGo rule engine.
|
Package funcs provides built-in function implementations for the RuleGo rule engine. |
|
processor
Package processor provides built-in processor implementations for the RuleGo endpoint system.
|
Package processor provides built-in processor implementations for the RuleGo endpoint system. |
|
components
|
|
|
action
Package action provides action node components for the RuleGo rule engine.
|
Package action provides action node components for the RuleGo rule engine. |
|
base
Package base provides foundational components and utilities for the RuleGo rule engine.
|
Package base provides foundational components and utilities for the RuleGo rule engine. |
|
external
Package external provides components for interacting with external systems and services in the RuleGo rule engine.
|
Package external provides components for interacting with external systems and services in the RuleGo rule engine. |
|
filter
Package filter provides filter node components for the RuleGo rule engine.
|
Package filter provides filter node components for the RuleGo rule engine. |
|
flow
Package flow provides components for managing sub-rule chains and component references in the RuleGo rule engine.
|
Package flow provides components for managing sub-rule chains and component references in the RuleGo rule engine. |
|
transform
Package transform provides transformation node components for the RuleGo rule engine.
|
Package transform provides transformation node components for the RuleGo rule engine. |
|
Package endpoint provides input endpoint components for the RuleGo rule engine.
|
Package endpoint provides input endpoint components for the RuleGo rule engine. |
|
impl
Package impl provides the core implementation of the endpoint module.
|
Package impl provides the core implementation of the endpoint module. |
|
mqtt
Package mqtt provides an MQTT endpoint implementation for the RuleGo framework.
|
Package mqtt provides an MQTT endpoint implementation for the RuleGo framework. |
|
net
Package net provides a network endpoint implementation for the RuleGo framework.
|
Package net provides a network endpoint implementation for the RuleGo framework. |
|
rest
Package rest provides an HTTP/REST endpoint implementation for the RuleGo framework.
|
Package rest provides an HTTP/REST endpoint implementation for the RuleGo framework. |
|
schedule
Package schedule provides a scheduled task endpoint implementation for the RuleGo framework.
|
Package schedule provides a scheduled task endpoint implementation for the RuleGo framework. |
|
websocket
Package websocket provides a WebSocket endpoint implementation for the RuleGo framework.
|
Package websocket provides a WebSocket endpoint implementation for the RuleGo framework. |
|
Package engine provides the core functionality for the RuleGo rule engine.
|
Package engine provides the core functionality for the RuleGo rule engine. |
|
examples
|
|
|
call_rest_service
command
|
|
|
custom_component
command
|
|
|
db_client
command
|
|
|
delay_node
command
|
|
|
functions_node
command
|
|
|
group_filter_node
command
|
|
|
hot_loading
command
|
|
|
http_endpoint
command
|
|
|
js_transform
command
|
|
|
mqtt_client
command
|
|
|
mqtt_endpoint_example/client
command
Package main demonstrates how to create an MQTT client that sends binary and JSON data to an MQTT endpoint server.
|
Package main demonstrates how to create an MQTT client that sends binary and JSON data to an MQTT endpoint server. |
|
mqtt_endpoint_example/server
command
Package main demonstrates how to create an MQTT endpoint server that processes binary and JSON data using JavaScript transform node.
|
Package main demonstrates how to create an MQTT endpoint server that processes binary and JSON data using JavaScript transform node. |
|
msg_type_switch
command
|
|
|
net_endpoint_example/client
command
Package main demonstrates how to create a NET client that sends binary data to a NET endpoint server.
|
Package main demonstrates how to create a NET client that sends binary data to a NET endpoint server. |
|
net_endpoint_example/server
command
Package main demonstrates how to create a NET endpoint server that processes binary and JSON data using JavaScript transform node.
|
Package main demonstrates how to create a NET endpoint server that processes binary and JSON data using JavaScript transform node. |
|
net_node
command
|
|
|
node_config
command
|
|
|
plugin
command
|
|
|
router
command
|
|
|
ssh_node
command
|
|
|
temperature_alarm
command
|
|
|
ui_api
command
|
|
|
web_api
command
|
|
|
Package node_pool provides shared node resource management for efficient connection reuse across different rule chains and components.
|
Package node_pool provides shared node resource management for efficient connection reuse across different rule chains and components. |
|
utils
|
|
|
aes
Package aes provides encryption and decryption functions using the AES algorithm.
|
Package aes provides encryption and decryption functions using the AES algorithm. |
|
fs
Package fs provides file system related utilities for the RuleGo project.
|
Package fs provides file system related utilities for the RuleGo project. |
|
js
Package js provides JavaScript execution capabilities for the RuleGo rule engine.
|
Package js provides JavaScript execution capabilities for the RuleGo rule engine. |
|
json
Package json provides utility functions for JSON marshaling, unmarshaling, and formatting.
|
Package json provides utility functions for JSON marshaling, unmarshaling, and formatting. |
|
maps
Package maps provides utility functions for working with maps and structs.
|
Package maps provides utility functions for working with maps and structs. |
|
mqtt
Package mqtt provides MQTT client functionality for the RuleGo rule engine.
|
Package mqtt provides MQTT client functionality for the RuleGo rule engine. |
|
pool
Package pool provides high-performance worker pool implementations for concurrent task execution.
|
Package pool provides high-performance worker pool implementations for concurrent task execution. |
|
reflect
Package reflect provides utility functions for reflection-based operations.
|
Package reflect provides utility functions for reflection-based operations. |
|
runtime
Package runtime provides utilities for runtime-related operations.
|
Package runtime provides utilities for runtime-related operations. |
|
str
Package str provides utility functions for string manipulation and processing.
|
Package str provides utility functions for string manipulation and processing. |