Share data
- Data Transmission Between Nodes
It is recommended to use Metadata
or Data
of msg
to transmit data between nodes. However, if you need to pass semaphores or pointer-like objects, context.Context
is also supported. Example of usage:
ruleEngine.OnMsg(msg, types.WithContext(context.WithValue(context.Background(), shareKey, shareValue)))
1
Component to obtain shared data:
func (n *TimeNode) OnMsg(ctx types.RuleContext, msg types.RuleMsg) {
// Obtain shared data via context
v1 := ctx.GetContext().Value(shareKey)
// Modify shared data via context
modifyCtx := context.WithValue(ctx.GetContext(), addShareKey, addShareValue)
ctx.SetContext(modifyCtx)
// Obtain shared data via msg.Metadata
v2 := msg.Metadata.GetValue("timestamp")
// Modify shared data via 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
2
3
4
5
6
7
8
9
10
11
12
13
- Data Sharing Across Rule Chains or Nodes
You can use [Cache][/pages/d59341/#cache] or Cache Set component Cache Get component Cache Delete component
Edit this page on GitHub (opens new window)
Last Updated: 2025/06/12, 01:18:51