Quick Start
# Installation
Use the go get
command to install RuleGo
:
go get github.com/rulego/rulego
1
# Usage
First, use Json format to define the rule chain. The rule chain definition does not require learning any specific rule syntax or DSL, just configure the components and connect them with a certain relationship, you can achieve your functional requirements. Reference rule chain
Using RuleGo is extremely simple and lightweight. Just 2 steps:
- Import the
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))
1
2
3
4
2
3
4
- Pass the message payload, message type, and message metadata to the rule engine instance for processing, and then the rule engine will process the message according to the rule chain definition:
//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)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Rule engine instance management:
//Get the created rule engine instance by rule chain ID
ruleEngine, ok := rulego.Get("rule01")
//Delete the created rule engine instance
rulego.Del("rule01")
1
2
3
4
2
3
4
# Example
You can run the examples/server
example project to speed up your understanding of how to use RuleGo.
Download address: Github (opens new window) Gitee (opens new window)
# Summary
Using RuleGo is extremely simple and lightweight. Just 2 steps:
- Use Json format rule chain to define business logic, and initialize the rule engine according to the rule chain.
- Then pass the message or event to the rule engine instance, and each message or event will be processed according to the logic defined by the rule chain. The rule chain supports hot update.
RuleGo is light but powerful, let's continue to explore the following chapters......
Edit this page on GitHub (opens new window)
Last Updated: 2024/10/23, 10:13:01