Giter Club home page Giter Club logo

Comments (3)

ogofly avatar ogofly commented on May 23, 2024

背景

我们在做的一个开源项目, 叫 tio,类似一个轻量的 iothub,计划加入一个规则引擎。
这个规则引擎作用主要是: 将设备的各种事件、MQTT 消息通过过滤、转换再输出到 MQTT 另外的 topic、数据库等。

问题

在过滤转换的过程中,需要消息本身之外的一些上下文信息,比如设备的基本信息、设备的 tag 信息等。

  1. 在使用 rulego 时,除了自定义一个 Node 来获取这些信息外,还有别的更合适的方式吗?
  2. rulego 会长期支持以库的方式被集成吗? —— 如果用自定义 Node 的方式来获取这些上下文信息,考虑到性能和延迟,一种可能的方式是希望与拥有上下文的程序在一个进程。

from rulego.

whki avatar whki commented on May 23, 2024

背景

我们在做的一个开源项目, 叫 tio,类似一个轻量的 iothub,计划加入一个规则引擎。 这个规则引擎作用主要是: 将设备的各种事件、MQTT 消息通过过滤、转换再输出到 MQTT 另外的 topic、数据库等。

问题

在过滤转换的过程中,需要消息本身之外的一些上下文信息,比如设备的基本信息、设备的 tag 信息等。

  1. 在使用 rulego 时,除了自定义一个 Node 来获取这些信息外,还有别的更合适的方式吗?
  2. 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.

ogofly avatar ogofly commented on May 23, 2024

感谢解答

from rulego.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.