同步操作将从 RuleGo/rulego 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
English| 中文
RuleGo
is a lightweight, high-performance, embedded, orchestrable component-based rule engine based on Go
language.
It is also a flexible and highly customizable event processing framework. Support heterogeneous system data integration. It can aggregate, distribute, filter, transform, enrich and execute various actions on input messages.
RuleGo documentation is hosted on: rulego.cc .
Go
, in addition, RuleGo
adopts technologies such as coroutine pool and object pool.RuleGo
into existing projects, non-intrusively utilizing its features.Go plugin
.Message type Switch
,JavaScript Switch
,JavaScript filter
,JavaScript converter
,HTTP push
,MQTT push
,Send email
,Log record
and other components. You can extend other components by yourself.RuleGo
is a rule engine based on orchestration, which is best at decoupling your system.
Go
language...
Then RuleGo
framework will be a very good solution.RuleGo
on the edge server, preprocess, filter, aggregate or calculate the data before reporting it to the cloud. The data processing rules and distribution rules can be dynamically configured and modified through the rule chain without restarting the system.RuleGo
as a glue to various different systems or protocols, such as: ssh,webhook,kafka, message queue, database, chatGPT, third-party systems.RuleGo
rule chain for management. Business requirements change without restarting the main program.RuleGo
to orchestrate and drive these custom components, and support dynamic adjustment.RuleGo
to orchestrate and drive microservices, or dynamically call third-party services to process business and return results.RuleGo Architecture Diagram
Use the go get
command to install RuleGo
:
go get github.com/rulego/rulego
First, define the rule chain in Json format. The rule chain definition does not require learning a specific rule syntax or DSL, just configure the components and connect them with certain relationships, and you can achieve your functional requirements. Rule chain definition: Reference rule chain
RuleGo is extremely simple and lightweight. Just follow these 2 steps:
RuleGo
package and use the rule chain definition to create a rule engine instance:import "github.com/rulego/rulego"
//Use the rule chain definition to create a rule engine instance
ruleEngine, err := rulego.New("rule01", []byte(ruleFile))
//Define message metadata
metaData := types.NewMetadata()
metaData.PutValue("productType", "test01")
//Define message payload and message type
msg := types.NewMsg(0, "TELEMETRY_MSG", types.JSON, metaData, "{\"temperature\":35}")
//Pass the message to the rule engine for processing
ruleEngine.OnMsg(msg)
Dynamically update the rule chain
//Update the root rule chain
err := ruleEngine.ReloadSelf([]byte(ruleFile))
//Update a node under the rule chain
ruleEngine.ReloadChild("rule_chain_test", nodeFile)
//Get the rule chain definition
ruleEngine.DSL()
Rule engine instance management:
//Load all rule chain definitions in the folder to the rule engine pool
rulego.Load("/rules", rulego.WithConfig(config))
//Get a created rule engine instance by ID
ruleEngine, ok := rulego.Get("rule01")
//Delete a created rule engine instance
rulego.Del("rule01")
Configuration:
See documentation for details
//Create a default configuration
config := rulego.NewConfig()
//Debug node callback, node configuration must be configured debugMode:true to trigger call
//Node entry and exit information will call this callback function
config.OnDebug = func (chainId,flowType string, nodeId string, msg types.RuleMsg, relationType string, err error) {
}
//Use configuration
ruleEngine, err := rulego.New("rule01", []byte(ruleFile), rulego.WithConfig(config))
Rule nodes are the basic components of the rule chain, they are functions that implement specific business logic. Rule nodes can filter, transform, enrich or perform some actions on the incoming messages. Rule nodes can adjust their behavior and output by configuring parameters.
You can easily encapsulate your business into RuleGo
node components, and flexibly configure and reuse them, like building blocks to achieve your business requirements.
go plugin
way: examples/plugin or documentation
RuleGo
provides a lot of standard components , as well as extended components
Rule chains are the core concept of RuleGo, they are directed acyclic graphs composed of multiple rule nodes, each rule node is a component that can implement different business logic, nodes are connected by relationship types (relation type). Rule chains can be dynamically configured and modified, support nesting and orchestration, and implement complex business processes.
The following example defines 3 rule nodes, which are to filter->transform->push data, the rule chain logic is as follows:
Rule chain definition:
{
"ruleChain": {
"name": "Test rule chain",
"root": true
},
"metadata": {
"nodes": [
{
"id": "s1",
"type": "jsFilter",
"name": "Filter",
"debugMode": true,
"configuration": {
"jsScript": "return msg!='bb';"
}
},
{
"id": "s2",
"type": "jsTransform",
"name": "Transform",
"debugMode": true,
"configuration": {
"jsScript": "metadata['test']='test02';\n metadata['index']=50;\n msgType='TEST_MSG_TYPE2';\n var msg2=JSON.parse(msg);\n msg2['aa']=66;\n return {'msg':msg2,'metadata':metadata,'msgType':msgType};"
}
},
{
"id": "s3",
"type": "restApiCall",
"name": "Push data",
"debugMode": true,
"configuration": {
"restEndpointUrlPattern": "http://192.168.216.21:9099/api/socket/msg",
"requestMethod": "POST",
"maxParallelRequestsCount": 200
}
}
],
"connections": [
{
"fromId": "s1",
"toId": "s2",
"type": "True"
},
{
"fromId": "s2",
"toId": "s3",
"type": "Success"
}
]
}
}
Other rule chain examples:
Asynchronous + sequential execution:
Using sub-rule chain method:
Some complex examples:
RuleGo
provides Endpoint
module for unified data integration and processing of heterogeneous systems.For more details, please refer to: Endpoint
RuleGo
almost does not increase system overhead, resource consumption is extremely low, especially suitable for running on edge servers.
In addition, RuleGo uses a directed acyclic graph to represent the rule chain, and each input message only needs to be processed along the path in the graph, without matching all the rules, This greatly improves the efficiency and speed of message processing, and also saves resources and time. The routing algorithm can achieve: no matter how many nodes the rule chain has, it will not affect the node routing performance.
Performance test cases:
Machine: Raspberry Pi 2 (900MHz Cortex-A7*4,1GB LPDDR2)
Data size: 260B
Rule chain: JS script filtering->JS complex transformation->HTTP push
Test results: 100 concurrent and 500 concurrent, memory consumption does not change much around 19M
Any form of contribution is welcome, including submitting issues, suggestions, documentation, tests or code. Please follow these steps:
RuleGo
uses Apache 2.0 license, please refer to LICENSE file for details.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。