RuleGo RuleGo
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • 快速入门

  • 规则链

  • 标准组件

  • 扩展组件

  • 自定义组件

  • 组件市场

  • 可视化

  • AOP

  • 触发器

  • 高级主题

    • Config
    • Options
    • 共享数据
    • 执行规则链
    • 组件配置变量
    • 组件连接复用
    • 性能
  • RuleGo-Server

  • 问题

共享数据

节点间共享数据,建议使用msg的Metadata或者Data,但如果需要传递信号量或者指针类,也支持context.Context 方式传递。

使用示例:

ruleEngine.OnMsg(msg, types.WithContext(context.WithValue(context.Background(), shareKey, shareValue)))
1

组件获取共享数据:


func (n *TimeNode) OnMsg(ctx types.RuleContext, msg types.RuleMsg)  {
	//context 方式获取共享数据
	v1 := ctx.GetContext().Value(shareKey)
	//context 方式修改共享数据
    modifyCtx := context.WithValue(ctx.GetContext(), addShareKey, addShareValue)
    ctx.SetContext(modifyCtx)
	
	//msg.Metadata 方式获取共享数据
    v2 :=msg.Metadata.GetValue("timestamp")
	//msg.Metadata 方式修改共享数据
    msg.Metadata.PutValue("timestamp", time.Now().Format(time.RFC3339))
	ctx.TellSuccess(msg)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
在 GitHub 上编辑此页 (opens new window)
上次更新: 2025/04/02, 01:29:50
Options
执行规则链

← Options 执行规则链→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式