RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

    • Config
    • Options
    • Share data
    • Execute Rule Chain
    • Component Configuration Variables
    • Component Connection Reuse
    • Performance
    • Other
  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

Share data

To share data between nodes, it is recommended to use the Metadata or Data of msg, but if you need to pass semaphores or pointers, you can also use the context.Context method.

Usage example:

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

Component to get shared data:


func (n *TimeNode) OnMsg(ctx types.RuleContext, msg types.RuleMsg)  {
	//context method to get shared data
	v1 := ctx.GetContext().Value(shareKey)
	//context method to modify shared data
    modifyCtx := context.WithValue(ctx.GetContext(), addShareKey, addShareValue)
    ctx.SetContext(modifyCtx)
	
	//msg.Metadata method to get shared data
    v2 :=msg.Metadata.GetValue("timestamp")
	//msg.Metadata method to modify shared data
    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
Edit this page on GitHub (opens new window)
Last Updated: 2025/04/02, 01:29:50
Options
Execute Rule Chain

← Options Execute Rule Chain→

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

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