# rulego
**Repository Path**: loozoo/rulego
## Basic Information
- **Project Name**: rulego
- **Description**: RuleGo是一个基于Go语言的轻量级、高性能、嵌入式、新一代组件编排规则引擎框架。⭐️你的Star,是我们前进的动力⭐️
- **Primary Language**: Go
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: https://rulego.cc
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 123
- **Created**: 2025-08-25
- **Last Updated**: 2025-11-20
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# RuleGo
[](https://pkg.go.dev/github.com/rulego/rulego)
[](https://goreportcard.com/report/github.com/rulego/rulego)
[](https://codecov.io/gh/rulego/rulego)
[](https://github.com/rulego/rulego/actions/workflows/test.yml)
[](https://github.com/rulego/rulego/actions/workflows/build.yml)
[](https://qm.qq.com/q/8RDaYcOry8)
[](https://github.com/avelino/awesome-go?tab=readme-ov-file#iot-internet-of-things)
[English](README.md)| 简体中文
**[我正在参加 Gitee 2025 最受欢迎的开源软件投票活动,快来给我投票吧!🔥 🔥 🔥 ](https://gitee.com/activity/2025opensource?ident=IM6TAN)**
[官网](https://rulego.cc) | [文档](https://rulego.cc/pages/0f6af2/) | [贡献指南](CONTRIBUTION_CN.md)
`RuleGo`是一个基于`Go`语言的轻量级、高性能、嵌入式、新一代组件编排规则引擎。它可以帮助你快速构建低耦合、灵活的系统,实时响应和调整业务需求变更。
`RuleGo` 还提供大量可复用的组件,支持对数据进行聚合、过滤、分发、转换、丰富和执行各种动作,也能和各种协议、系统进行联动和集成。
它在低代码、业务代码编排、数据集成、工作流、大模型智能体、边缘计算、自动化、IoT等多种场景具有广泛的应用潜力。
RuleGo架构图
## 规则链运行示例图
[更多运行模式](http://8.134.32.225:9090/ui/)
## 安装
使用`go get`命令安装`RuleGo`:
```bash
go get github.com/rulego/rulego
```
或者使用gitee/gitcode源
```bash
go get gitee.com/rulego/rulego
#or
go get gitcode.com/rulego/rulego
```
## 使用
`RuleGo` 使用很简单。只需以下3步:
1. 使用JSON定义规则链:
- [规则链DSL文档](https://rulego.cc/pages/10e1c0/)
- [example_chain.json](testdata/rule/chain_call_rest_api.json)
2. 导入`RuleGo`包,并使用规则链定义,创建一个规则引擎实例:
```go
import "github.com/rulego/rulego"
//加载规则链定义文件
ruleFile := fs.LoadFile("chain_call_rest_api.json")
//使用规则链定义,创建一个规则引擎实例
ruleEngine, err := rulego.New("rule01", ruleFile)
```
3. 把消息负荷、消息类型、消息元数据交给规则引擎实例处理,然后规则引擎就会根据规则链的定义处理消息:
```go
//定义消息元数据
metaData := types.NewMetadata()
metaData.PutValue("productType", "test01")
//定义消息负荷和消息类型
msg := types.NewMsg(0, "TELEMETRY_MSG", types.JSON, metaData, "{\"temperature\":35}")
//把消息交给规则引擎处理
ruleEngine.OnMsg(msg)
```
>可以在不重启应用的情况下实时更新规则链逻辑
### 规则引擎管理API
- 动态更新规则链
```go
//动态更新规则链逻辑
err := ruleEngine.ReloadSelf(ruleFile)
//更新规则链下某个节点
ruleEngine.ReloadChild("node01", nodeFile)
//获取规则链定义
ruleEngine.DSL()
```
- 规则引擎实例管理:
```go
//加载文件夹所有规则链定义到规则引擎池
rulego.Load("/rules", rulego.WithConfig(config))
//通过ID获取已经创建的规则引擎实例
ruleEngine, ok := rulego.Get("rule01")
//删除已经创建的规则引擎实例
rulego.Del("rule01")
```
- 配置:[文档](https://rulego.cc/pages/d59341/)
```go
//创建一个默认的配置
config := rulego.NewConfig()
//调试节点回调,节点配置必须配置debugMode:true 才会触发调用
//节点入和出信息都会调用该回调函数
config.OnDebug = func (chainId,flowType string, nodeId string, msg types.RuleMsg, relationType string, err error) {
}
//使用配置
ruleEngine, err := rulego.New("rule01", []byte(ruleFile), rulego.WithConfig(config))
```
### 规则链定义
[规则链定义DSL](https://rulego.cc/pages/10e1c0/)
### 规则链节点组件
`RuleGo` 的核心特性是组件化,所有业务逻辑都是组件,并能灵活配置和重用它们。目前RuleGo 已经内置了大量常用的组件。
- [标准组件](https://rulego.cc/pages/88fc3c/)
- [rulego-components](https://github.com/rulego/rulego-components) :[文档](https://rulego.cc/pages/d7fc43/)
- [rulego-components-ai](https://github.com/rulego/rulego-components-ai)
- [rulego-components-ci](https://github.com/rulego/rulego-components-ci)
- [rulego-components-iot](https://github.com/rulego/rulego-components-iot)
- [rulego-components-etl](https://github.com/rulego/rulego-components-etl)
- [rulego-marketplace](https://github.com/rulego/rulego-marketplace) :动态组件和规则链市场
- [自定义节点组件示例](examples/custom_component) :[文档](https://rulego.cc/pages/caed1b/)
## 数据集成
`RuleGo` 提供`Endpoint`规则引擎输入端模块,对异构系统进行统一的数据接入和集成。详细参考: [Endpoint](endpoint/README_ZH.md)
### Endpoint输入端组件
- [Endpoint组件](https://rulego.cc/pages/691dd3/)
- [Endpoint DSL](https://rulego.cc/pages/390ad7/)
### RuleGo-Server
我们提供了一个基于`RuleGo`的开箱即用自动化工作流平台:[RuleGo-Server](https://github.com/rulego/rulego-server) ,
以及配套的前端可视化编辑器:[RuleGo-Editor](https://editor.rulego.cc/) 。
## 性能
`RuleGo` 大部分工作都在初始化时完成,执行规则链时几乎不会额外增加系统开销,资源占用极低,特别适合在边缘服务器运行。
另外RuleGo使用有向无环图来表示规则链,每个输入消息只需要沿着图中的路径进行处理,无需匹配所有的规则, 这大大提高了消息处理和路由的效率,也节省了系统资源。
性能测试用例:
```
机器:树莓派2(900MHz Cortex-A7*4,1GB LPDDR2)
数据大小:260B
规则链:JS脚本过滤->JS复杂转换->HTTP推送
测试结果:100并发和500并发,内存占用变化不大都在19M左右
```
[更多性能测试用例](https://rulego.cc/pages/f60381/)
## 生态
- [RuleGo-Editor](https://editor.rulego.cc/) :规则链可视化编辑器
- [RuleGo-Server](https://github.com/rulego/rulego-server) :自动化工作流平台
- [rulego-components](https://gitee.com/rulego/rulego-components) :扩展组件库
- [rulego-components-ai](https://github.com/rulego/rulego-components-ai) :AI场景组件库
- [rulego-components-ci](https://github.com/rulego/rulego-components-ci) :CI/CD场景组件库
- [rulego-components-iot](https://github.com/rulego/rulego-components-iot) :IoT场景组件库
- [rulego-components-etl](https://github.com/rulego/rulego-components-etl) :ETL场景组件库
- [rulego-marketplace](https://github.com/rulego/rulego-marketplace) :动态组件和规则链市场
## 贡献
欢迎任何形式的贡献,包括提交问题、建议、文档、测试或代码。[贡献指南](CONTRIBUTION_CN.md)
## 交流群
QQ群号:**720103251**
微信(加好友拉入群):**rulegoteam**
## 许可
`RuleGo`使用Apache 2.0许可证,详情请参见[LICENSE](LICENSE)文件。