@@ -152,24 +152,57 @@ StreamSQL 提供灵活的日志配置选项:
152152 // 禁用日志(生产环境)
153153 ssql := streamsql.New(streamsql.WithDiscardLog())
154154
155- # 性能配置
155+ # 与RuleGo集成
156156
157- 对于生产环境,建议进行以下配置 :
157+ StreamSQL提供了与RuleGo规则引擎的深度集成,通过两个专用组件实现流式数据处理 :
158158
159- ssql := streamsql.New(
160- streamsql.WithDiscardLog(), // 禁用日志提升性能
161- // 其他配置选项...
162- )
159+ • streamTransform (x/streamTransform) - 流转换器,处理非聚合SQL查询
160+ • streamAggregator (x/streamAggregator) - 流聚合器,处理聚合SQL查询
163161
164- # 与RuleGo集成
162+ 基本集成示例:
165163
166- StreamSQL可以与RuleGo规则引擎无缝集成,利用RuleGo丰富的组件生态:
164+ package main
167165
168- // TODO: 提供RuleGo集成示例
166+ import (
167+ "github.com/rulego/rulego"
168+ "github.com/rulego/rulego/api/types"
169+ // 注册StreamSQL组件
170+ _ "github.com/rulego/rulego-components/external/streamsql"
171+ )
169172
170- 更多详细信息和高级用法,请参阅:
171- • 自定义函数开发指南: docs/CUSTOM_FUNCTIONS_GUIDE.md
172- • 快速入门指南: docs/FUNCTION_QUICK_START.md
173- • 完整示例: examples/
173+ func main() {
174+ // 规则链配置
175+ ruleChainJson := `{
176+ "ruleChain": {"id": "rule01"},
177+ "metadata": {
178+ "nodes": [{
179+ "id": "transform1",
180+ "type": "x/streamTransform",
181+ "configuration": {
182+ "sql": "SELECT deviceId, temperature * 1.8 + 32 as temp_f FROM stream WHERE temperature > 20"
183+ }
184+ }, {
185+ "id": "aggregator1",
186+ "type": "x/streamAggregator",
187+ "configuration": {
188+ "sql": "SELECT deviceId, AVG(temperature) as avg_temp FROM stream GROUP BY deviceId, TumblingWindow('5s')"
189+ }
190+ }],
191+ "connections": [{
192+ "fromId": "transform1",
193+ "toId": "aggregator1",
194+ "type": "Success"
195+ }]
196+ }
197+ }`
198+
199+ // 创建规则引擎
200+ ruleEngine, _ := rulego.New("rule01", []byte(ruleChainJson))
201+
202+ // 发送数据
203+ data := `{"deviceId":"sensor01","temperature":25.5}`
204+ msg := types.NewMsg(0, "TELEMETRY", types.JSON, types.NewMetadata(), data)
205+ ruleEngine.OnMsg(msg)
206+ }
174207*/
175208package streamsql
0 commit comments