You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/developing-flows/designing.md
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,11 @@ If a project needs complicated logic, it is better to design flow before startin
14
14
* Implementation
15
15
16
16
### Designing flow structure
17
-
<!-- >
17
+
18
+
{% comment %}
18
19
*As the size of flows in a tab gets larger, it can be difficult to recognize a function of each flow within a tab. To improve reusability of flows, it would be better to decide the responsibility of flows within each tab and the scale of one tab. To do this, it is helpful to sort out what kind of things, people, work, rules are in the target domain of the application, and relationship of them.*
19
-
-->
20
+
{% endcomment %}
21
+
20
22
#### Designing flow within a tab
21
23
22
24
There is a case that one application is constructed by multiple function. For example, if you are developing an application that detects temperature and humidity with a sensor and sounds an alert on an external device, you should complete each function within one flow because it is likely that a mix of function logic, such as sensor, threshold identification, and access to the device, will be complicated.
@@ -49,9 +51,10 @@ For example, if the process of sending e-mail is written as a sub-flow, it can b
49
51
### Designing messages
50
52
51
53
There are risks that multiple nodes have dependencies by messages passing through nodes. For other developers to reuse flows, it is important to design messages so that dependencies get to be relaxed.
52
-
<!--
54
+
55
+
{% comment %}
53
56
This chapter proposes a guide about designing message.
54
-
-->
57
+
{% endcomment %}
55
58
56
59
Messages that travel the flow are in the form of a JavaScript object with the object name typically referred as `msg`.
57
60
Although these messages are partially affected by the restrictions of Node-RED and Node.js and the execution model, the ability to give the message object any attributes and assign it values of any data type makes it highly flexible.
@@ -73,17 +76,17 @@ Therefore, like the flow structure, appropriate message design is an important f
73
76
Note that it is possible for the design of the message to influence the system design.
74
77
You better to design the messages before implementing a flow.
75
78
76
-
<!--
79
+
{% comment %}
77
80
*We have already written actual contents on [here](https://github.com/node-red/node-red.github.io/wiki/Flow-Guideline-Contents).*
78
-
-->
81
+
{% endcomment %}
79
82
80
83
#### Designing key-value structure of `msg`
81
84
82
-
<!--
85
+
{% comment %}
83
86
*`msg` is a JavaScript object that contains a key-value structure like JSON. While a `msg` transits across multiple nodes, the nodes use some keys and values of the `msg`. If two or more nodes of them use the same key for different their own purposes, preparing `msg` for input of the nodes is so difficult.*
84
87
85
88
*Therefore, strategy of key-value structure are needed and this subsection describes it as followings,*
86
-
-->
89
+
{% endcomment %}
87
90
88
91
There are no naming restrictions that apply to the property names of `msg` objects. Consequently, there is a risk that multiple nodes will unintentionally use the same property.
89
92
To mitigate this issue, a design strategy is preferably in place whereby the parameters in which data is stored in the `msg` object are predetermined for each type of data.
@@ -119,20 +122,20 @@ In addition, the first node of the flow verifies that the message received as in
119
122
Properties other than those expected can be used freely in the flow.
120
123
This verification process also expresses the boundaries of dependencies between flows.
121
124
122
-
<!--
125
+
{% comment %}
123
126
**Top-level keys of `msg` are used to control the functionality of node*
124
127
**`msg.payload` is used as input parameters of a process of a node*
125
-
-->
128
+
{% endcomment %}
126
129
127
130
#### Keeping properties
128
131
129
132
In the case of using `Function` node, you can prepare output messages by creating new `msg` objects. However, the output messages may not have some properties that the input message has. This means that properties that should be kept in your flow has lost. Since this can be a cause of serious bugs, preparing output messages based on an input message is better, instead of creating new `msg`.
130
133
131
134
#### Add tag into `msg` to distinguish a node that sent the `msg`
132
135
133
-
<!--
136
+
{% comment %}
134
137
*[Tips] If it is needed that a (latter) node executes a different process depending on a (former) node that send `msg`, former node adds tags describing the former node itself. With the tag, the latter node decide the process to execute.*
135
-
-->
138
+
{% endcomment %}
136
139
137
140
Nodes can have multiple output ports, but only one input port. Messages moving through the flow include messages that control nodes and messages that provide data to be processed. When there is a need to distinguish among different types of input messages on each path of a flow, you should do so using properties in the message.
138
141
@@ -145,9 +148,10 @@ Specifically, you assign a tag that identifies the execution path as a message p
145
148
#### Using persistent storage outside of Node-RED
146
149
147
150
If you handle the large amount of data, it is **not** recommended to set the data into `msg` since `msg` can exhaust available memory.
148
-
<!--
151
+
152
+
{% comment %}
149
153
Instead, you had better put the data on a persistent storage that is outside of Node-RED and use reference to the data for handling the data.*
150
-
-->
154
+
{% endcomment %}
151
155
152
156
Because messages are held in memory, sending messages that contain large amounts of data significantly impacts processing time and memory usage.
153
157
The processing of Node-RED will come to a standstill when memory is exhausted.
@@ -177,7 +181,7 @@ That is, your flow should produce the correct result even if messages arrive in
177
181
178
182
If you want to design the flow depending on messages in order, you should use `Sort` node. You can check how to use `Sort` node at **Sequential guarantee** of [Non-functional requirements](non-functional).
179
183
180
-
<!--
184
+
{% comment %}
181
185
If you want to assume processes by the order of arrival, try this code.
0 commit comments