Comments (3)
背景
我们在做的一个开源项目, 叫 tio,类似一个轻量的 iothub,计划加入一个规则引擎。
这个规则引擎作用主要是: 将设备的各种事件、MQTT 消息通过过滤、转换再输出到 MQTT 另外的 topic、数据库等。
问题
在过滤转换的过程中,需要消息本身之外的一些上下文信息,比如设备的基本信息、设备的 tag 信息等。
- 在使用 rulego 时,除了自定义一个 Node 来获取这些信息外,还有别的更合适的方式吗?
- rulego 会长期支持以库的方式被集成吗? —— 如果用自定义 Node 的方式来获取这些上下文信息,考虑到性能和延迟,一种可能的方式是希望与拥有上下文的程序在一个进程。
from rulego.
背景
我们在做的一个开源项目, 叫 tio,类似一个轻量的 iothub,计划加入一个规则引擎。 这个规则引擎作用主要是: 将设备的各种事件、MQTT 消息通过过滤、转换再输出到 MQTT 另外的 topic、数据库等。
问题
在过滤转换的过程中,需要消息本身之外的一些上下文信息,比如设备的基本信息、设备的 tag 信息等。
- 在使用 rulego 时,除了自定义一个 Node 来获取这些信息外,还有别的更合适的方式吗?
- rulego 会长期支持以库的方式被集成吗? —— 如果用自定义 Node 的方式来获取这些上下文信息,考虑到性能和延迟,一种可能的方式是希望与拥有上下文的程序在一个进程。
问题一
规则链的消息(types.RuleMsg),会贯彻在整个规则链。 types.RuleMsg 主要包含几部分
- type: 事件/消息类型
- data: 消息payload
- metadata: 元数据,这个元数据的设计就是为了存放:设备的基本信息、设备的 tag 信息。建议您说的上下文信息存放在这里。
例如:
metaData := types.NewMetadata()
metaData.PutValue("productType", "productType01")
metaData.PutValue("name", "test")
msg := types.NewMsg(0, "TEST_MSG_TYPE", types.JSON, metaData, "{\"aa\":\"aaaaaaaaaaaaaa\"}")
ruleEngine.OnMsg(msg)
如果是指针类型或者其他共享变量,也可以通过context.Context方式传递上下文。然后组件通过以下方式获取:
v := ctx.GetContext().Value(shareKey)
参考:TestWithContext
参考:component_test
问题二
rulego 会长期支持以库的方式被集成。
- 通过metadata方式传递上下文,从目前的测试来看(包括在树莓派2上测试),没有太大性能的损耗,而且是上下文安全。
- 通过context.Context方式传递上下文,是函数调用方式,不会有性能和延迟问题。
from rulego.
感谢解答
from rulego.
Related Issues (12)
- 是单机版的吗?未来路线图种有集群化发展的考虑吗? HOT 1
- hope more developers can contribute extension components to RuleGo
- 请问有Hook(或者类似的机制)吗 HOT 4
- 节点依赖未生效 HOT 4
- Python runtime支持 HOT 3
- 请教下规则链部分的架构**是什么? HOT 1
- fatal error: concurrent map writes
- 是否支持空链,目前初始化空链后,onMsg 程序会直接 panic HOT 1
- How does the restApiCall component add HTTP basic authentication credentials? HOT 2
- Does restApiCall or net support the grpc protocol HOT 1
- 如何保证流程中断后重启 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rulego.