

RuleGo是一个基于Go语言的轻量级、高性能、嵌入式的规则引擎。也一个灵活配置和高度定制化的事件处理框架。可以对输入消息进行过滤、转换、丰富和执行各种动作。
使用Apache-2.0开源协议
规则链是规则节点及其关系的逻辑组。接收来自节点的出站消息将其通过指定关系发送至下一个或多个节点。以下是一些常用的规则链例子:




RuleGo是一个基于Go语言的轻量级、高性能、嵌入式的规则引擎。也一个灵活配置和高度定制化的事件处理框架。可以对输入消息进行过滤、转换、丰富和执行各种动作。
本项目很大程度受thingsboard 启发。参考其规则链思想,但在架构上做了重大调整,来满足以下场景:
使用go get命令安装RuleGo:
go get github.com/rulego/rulegohttps://github.com/rulego/rulego/blob/main/README_ZH.md#%E4%BD%BF%E7%94%A8
使用Json格式定义规则链DSL:
以下例子定义3个规则节点,规则链逻辑如下图:(更多例子参考testcases/)

{
"ruleChain": {
"name": "测试规则链",
"root": true
},
"metadata": {
"nodes": [
{
"id": "s1",
"type": "jsFilter",
"name": "过滤",
"debugMode": true,
"configuration": {
"jsScript": "return msg!='bb';"
}
},
{
"id": "s2",
"type": "jsTransform",
"name": "转换",
"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": "推送数据",
"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"
}
],
"ruleChainConnections": null
}
}详细内容请查看 README.md 文档。
rulego 几乎不会额外增加系统开销,资源占用极低,因为使用了对象协程池和对象池,甚至比直接调用业务的方式性能还高,特别适合在边缘服务器运行。
机器:树莓派2(900MHz Cortex-A7*4,1GB LPDDR2) 数据大小:260B 规则链:JS脚本过滤->JS复杂转换->HTTP推送 测试结果:100并发和500并发,内存占用变化不大都在19M左右