# RuleGo
English| [中文](README_ZH.md)
<img src="doc/imgs/logo.png" width="100">
`RuleGo` is a lightweight, high-performance, embedded rule engine based on `Go` language. It is also a flexible and highly customizable event processing framework. It can aggregate, distribute, filter, transform, enrich and execute various actions on input messages.
This project is largely inspired by [thingsboard](https://github.com/thingsboard/thingsboard) .
## Features
* Development language: Go 1.18
* Lightweight: No external middleware dependencies, can efficiently process and link data on low-cost devices, suitable for IoT edge computing.
* High performance: Thanks to the high-performance characteristics of `Go`, in addition, `RuleGo` adopts technologies such as coroutine pool and object pool. For 10W data processing `JS script filtering->JS script data processing->HTTP push`, the average time is 9 seconds.
* Embedded: Support embedding `RuleGo` into existing projects, non-intrusively utilizing its features.
* Componentized: All business logic is componentized and can be flexibly configured and reused.
* Rule chain: You can flexibly combine and reuse different components to achieve highly customizable and scalable business processes.
* Process orchestration: Support dynamic orchestration of rule chains, you can encapsulate your business into `RuleGo` components, and then achieve your highly changing business needs by building blocks.
* Easy to extend: Provide rich and flexible extension interfaces and hooks, such as: custom components, component registration management, rule chain DSL parser, coroutine pool, rule node message inflow/outflow callback, rule chain processing end callback.
* Dynamic loading: Support dynamic loading of components and extension components through `Go plugin`.
* Built-in common components: `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.
* Context isolation mechanism: Reliable context isolation mechanism, no need to worry about data streaming in high concurrency situations.
## Use Cases
`RuleGo` is a rule engine based on orchestration, which is best at decoupling your system.
- If your system is complex and bloated with code
- If your business scenario is highly customized or frequently changed
- Or you need an end-to-end IoT solution
- Or you need to process data from heterogeneous systems centrally
- Or you want to try hot deployment in `Go` language...
Then `RuleGo` framework will be a very good solution.
#### Typical use cases
* **Edge computing:** For example: You can deploy `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.
* **Internet of Things:** For example: Collect device data reporting, and after the rule judgment of the rule chain, trigger one or more actions, such as: send email, send alarm, and link with other devices or systems.
* **Data distribution:** For example: You can distribute data to different systems according to different message types, such as HTTP, MQTT or gRPC.
* **Application integration:** For example: kafka, message queue, third-party system integration.
* **Data processing from heterogeneous systems:** For example: Receive data from different data sources (such as MQTT, HTTP, etc.), and then filter, format conversion, and then distribute to databases, business systems or dashboards.
* **Highly customized business:** For example: Decouple highly customized or frequently changed business and hand it over to `RuleGo` rule chain for management. Business requirements change without restarting the main program.
* **Complex business orchestration:** For example: Encapsulate the business into custom components, and use `RuleGo` to orchestrate and drive these custom components, and support dynamic adjustment.
* **Microservice orchestration:** For example: Use `RuleGo` to orchestrate and drive microservices, or dynamically call third-party services to process business and return results.
* **Business code and business logic decoupling:** For example: User points calculation system, risk control system.
* **Flexible configuration and highly customized event processing framework:** For example: Asynchronously or synchronously process different message types.
## Installation
Use the `go get` command to install `RuleGo`:
```bash
go get github.com/rulego/rulego
```
## Usage
Use Json format to define the rule chain DSL:
The following example defines 3 rule nodes, and the rule chain logic is as follows: (For more examples, refer to [testcases/](testcases))
<img src="doc/imgs/rulechain/img_1.png" style="height:50%;width:80%;">
```json
{
"ruleChain": {
"name": "Test rule chain",
"root": true,
"debugMode": false
},
"metadata": {
"nodes": [
{
"id": "s1",
"type": "jsFilter",
"name": "Filtering Data",
"debugMode": true,
"configuration": {
"jsScript": "return msg!='bb';"
}
},
{
"id": "s2",
"type": "jsTransform",
"name": "Transform Data",
"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": "Call Rest Api 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"
}
],
"ruleChainConnections": null
}
}
```
Description:
- `ruleChain`: The root object of the rule chain definition, which contains the following fields:
- `name`: The name of the rule chain, which can be any string.
- `root`: A boolean value indicating whether this rule chain is the root rule chain or a sub-rule chain. Only one root rule chain is allowed per rule engine instance.
- `debugMode`: A boolean value indicating whether this rule chain is in debug mode or not. If true, the debug callback function will be triggered when the rule chain processes messages.
- `metadata`: An object that contains the information of the nodes and connections in the rule chain, which has the following fields:
- `nodes`: An array of objects, each representing a rule node in the rule chain. Each node object has the following fields:
- `id`: A unique identifier for the node, which can be any string.
- `type`: The type of the node, which determines the logic and behavior of the node. It should match one of the registered node types in the rule engine.
- `name`: The name of the node, which can be any string.
- `debugMode`: A boolean value indicating whether this node is in debug mode or not. If true, the debug callback function will be triggered when the node processes messages.
- `configuration`: An object that contains the configuration parameters for the node, which vary depending on the node type. For example, a JS filter node may have a `jsScript` field that defines the filtering logic, while a REST API call node may have a `restEndpointUrlPattern` field that defines the URL to call.
- `connections`: An array of objects, each repr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
RuleGo是一个基于Go语言的轻量级、高性能、嵌入式的规则引擎。也一个灵活配置和高度定制化的事件处理框架。可以对输入消息进行聚合、分发、过滤、转换、丰富和执行各种动作。 本项目很大程度受thingsboard 启发。 特性 开发语言:Go 1.18 轻量级:无外部中间件依赖,在低成本设备中也能高效对数据进行处理和联动,适用于物联网边缘计算。 高性能:得益于Go的高性能特性,另外RuleGo采用协程池和对象池等技术。对10W条数据进行JS脚本过滤->JS脚本数据转换->HTTP推送 处理,平均用时9秒。 嵌入式:支持把RuleGo嵌入到现有项目,非入侵式利用其特性。 组件化:所有业务逻辑都是组件,并能灵活配置和重用它们。 规则链:可以灵活地组合和重用不同的组件,实现高度定制化和可扩展性的业务流程。 流程编排:支持对规则链进行动态编排,你可以把业务地封装成RuleGo组件,然后通过搭积木方式实现你高度变化的业务需求。 扩展简单:提供丰富灵活的扩展接口和钩子,如:自定义组件、组件注册管理、规则链DSL解析器、协程池、规则节点消息流入/流出回调、规则链处理结束回调。 动态加载:支持通过G
资源推荐
资源详情
资源评论
收起资源包目录
rulego-main.zip (76个子文件)
rulego-main
pool
workerpool.go 5KB
workerpool_b_test.go 1KB
workerpool_test.go 1KB
engine_test.go 5KB
go.mod 594B
go.sum 7KB
doc
imgs
logo.png 23KB
rulechain
img_3.png 21KB
img_4.png 23KB
img_1.png 8KB
img_2.png 28KB
qq.png 68KB
LICENSE 11KB
README_ZH.md 15KB
api
README_ZH.md 2KB
types
logger.go 1KB
config.go 4KB
types.go 8KB
msg.go 3KB
server
msg_handlers.go 1KB
rule_handlers.go 2KB
server.go 4KB
mqtt.go 2KB
README.md 2KB
说明.txt 48B
testcases
rule_engine_b_test.go 3KB
chain_has_sub_chain.json 950B
chain_call_rest_api.json 1KB
not_debug_mode_chain.json 811B
rule_engine_test.go 12KB
plugin
plugin.go 2KB
plugin_test.go 3KB
test_context_chain.json 501B
filter_node.json 549B
sub_chain.json 837B
chain_msg_type_switch.json 1KB
component_test.go 2KB
utils
str
str_test.go 2KB
str.go 4KB
json
json.go 1KB
json_test.go 949B
maps
maps_test.go 1KB
maps.go 925B
node.go 2KB
components
mqtt
client.go 5KB
js
js_engine.go 3KB
js_engine_test.go 2KB
transform
js_transform_node_test.go 2KB
js_transform_node.go 4KB
registry.go 716B
filter
js_filter_node.go 3KB
js_switch_node.go 3KB
js_filter_node_test.go 2KB
msg_type_switch_node_test.go 1KB
js_switch_node_test.go 1KB
msg_type_switch_node.go 1KB
registry.go 713B
action
rest_api_call_node_test.go 1KB
send_email_node.go 5KB
js_log_node_test.go 1KB
mqtt_client_node.go 3KB
send_mail_node_test.go 3KB
mqtt_client_node_test.go 1KB
js_log_node.go 3KB
rest_api_call_node.go 5KB
registry.go 713B
chain.go 9KB
dsl.go 5KB
test
test.go 3KB
assert
assertions.go 3KB
parser.go 1KB
.gitignore 574B
engine.go 11KB
README.md 17KB
rulego.go 2KB
registry.go 5KB
共 76 条
- 1
资源评论
你的月亮和太阳
- 粉丝: 211
- 资源: 91
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- c语言文件读写操作代码.txt
- Java 8+ 函数式编程速查表.zip
- raw文件如何打开-摄影领域的RAW文件处理与编辑解决方案
- Java 8 字符串操作库 .zip
- Java 8 功能.zip
- Java , JavaFX , Kotlin 游戏库(引擎).zip
- IPinfo API 的官方 Java 库(IP 地理位置和其他类型的 IP 数据).zip
- IntelliJ IDEA 针对 Square 的 Java 和 Android 项目的代码样式设置 .zip
- Gradle,Maven 插件将 Java 应用程序打包为原生 Windows、MacOS 或 Linux 可执行文件并为其创建安装程序 .zip
- Google Maps API Web 服务的 Java 客户端库.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功