-
Notifications
You must be signed in to change notification settings - Fork 1
/
batcher.html
206 lines (192 loc) · 7.73 KB
/
batcher.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!--
Copyright 2015 Awear Solutions Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="batcher">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row" id="node-maxTopics">
<label for="node-input-maxTopics">Max Topics</label>
<input type="number" id="node-input-maxTopics" placeholder="Maximal number of topics to cache" />
</div>
<div class="form-row" id="node-maxMessagesPerTopic">
<label for="node-input-maxMessagesPerTopic">Max Messages Per Topic</label>
<input type="number" id="node-input-maxMessagesPerTopic" placeholder="Maximal number of messages per topic to cache" />
</div>
<div class="form-row" id="node-maxDelay">
<label for="node-input-maxDelay">Max Delay (ms)</label>
<input type="number" id="node-input-maxDelay" placeholder="Maximal time that a message can wait in cache (milliseconds)" />
</div>
</script>
<script type="text/x-red" data-help-name="batcher">
<p>Collects message payloads by topic and sends them in a batch (array) when:</p>
<p>
<ul>
<li>The number of messages in the given topic reaches the configured maximal value.</li>
<li>The number of unique topics in cache crosses the configured limit (flushes the topic of the oldest message in the cache).</li>
<li>A message with a non-true payload (false, null, undefined, empty-string...) arrives. If the topic is non-true, all the cache will be flushed, otherwise only the given topic will be flushed.</li>
<li>The oldest message in cache of a given topic waits for more than the maximal delay time (use a negative value to disable feature).</li>
</ul>
</p>
</script>
<script type="text/x-red" data-template-name="debouncer">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row" id="node-maxTopics">
<label for="node-input-maxTopics">Max Topics</label>
<input type="text" id="node-input-maxTopics" placeholder="Maximal number of topics to cache" />
</div>
<div class="form-row" id="node-interval">
<label for="node-input-interval">Interval (ms)</label>
<input type="number" id="node-input-interval" placeholder="Minimal time between messages of the same topic (milliseconds)" />
</div>
</script>
<script type="text/x-red" data-help-name="debouncer">
<p>
When a message with a new topic arrives, the message is saved and a new timer is created.<br/>
When a new message with the same topic arrives before the timer has expired, it replaces the save message.<br/>
When the timer expires, the last saved message of the topic is sent (and the topic is "forgotten" - will be treated as a "new topic" next time).
The same will happen if a message with a non-true payload arrives (for the topic of that message). If the topic is non-true, this will be done for all topics.<br/>
If the number of timers (i.e. unique topics) crosses the configured limit, the timer of the oldest topic will be cleared and its message will be sent.<br/>
The debouncer node is very similar to the batcher node, but instead of saving all the messages it saves only the last message.
</p>
</script>
<script type="text/x-red" data-template-name="rate-limit">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row" id="node-maxTopics">
<label for="node-input-maxTopics">Max Topics</label>
<input type="text" id="node-input-maxTopics" placeholder="Maximal number of topics to cache" />
</div>
<div class="form-row" id="node-maxMessagesPerTopic">
<label for="node-input-maxMessagesPerTopic">Max Messages Per Topic</label>
<input type="number" id="node-input-maxMessagesPerTopic" placeholder="Maximal number of messages per topic to cache" />
</div>
<div class="form-row" id="node-dropOverflowMessages">
<label> </label>
<input type="checkbox" id="node-input-dropOverflowMessages" style="display: inline-block; width: auto; vertical-align: top;" />
<label for="node-input-dropOverflowMessages" style="width: 70%;">Drop Overflow Messages</label>
</div>
<div class="form-row" id="node-interval">
<label for="node-input-interval">Interval (ms)</label>
<input type="number" id="node-input-interval" placeholder="Minimal time between messages of the same topic (milliseconds)" />
</div>
</script>
<script type="text/x-red" data-help-name="rate-limit">
<p>
When a message with a new topic arrives, the message is sent and a new interval is created.<br/>
When a new message with the same topic arrives and the interval is running, and the queue is not full, it is added to a queue.<br/>
If the queue is full (according to "Max Messages Per Topic"), and "Drop Overflow Messages" is set, the new message is ignored.<br/>
If the queue is full but "Drop Overflow Messages" is unset, the queue is flushed and the new message is sent immediately after
(as if this was a message with a new topic)<br/>
On each interval tick, the next message in the queue is sent.
If there are no more messages in the queue, the interval is cleared.<br/>
If a message with a non-true payload arrives all messages will be flushed immediately (for the topic of that message).
If the topic is non-true, this will be done for all topics.<br/>
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('batcher', {
category: 'function',
defaults: {
name: {
value: ""
},
maxTopics: {
value: 1,
validate: RED.validators.number()
},
maxMessagesPerTopic: {
value: 10,
validate: RED.validators.number()
},
maxDelay: {
value: -1,
validate: RED.validators.number()
}
},
color: "rgb(235, 176, 100)",
inputs: 1,
outputs: 1,
icon: "batcher.png",
label: function() {
return this.name || "batcher";
},
labelStyle: function() {
return (this.name?"node_label_italic":"");
}
});
RED.nodes.registerType('debouncer', {
category: 'function',
defaults: {
name: {
value: ""
},
maxTopics: {
value: 1000000,
validate: RED.validators.number()
},
interval: {
value: 1000,
validate: RED.validators.number()
}
},
color: "rgb(235, 176, 100)",
inputs: 1,
outputs: 1,
icon: "timer.png",
label: function() {
return this.name || "debouncer";
},
labelStyle: function() {
return (this.name?"node_label_italic":"");
}
});
RED.nodes.registerType('rate-limit', {
category: 'function',
defaults: {
name: {
value: ""
},
maxTopics: {
value: 1000000,
validate: RED.validators.number()
},
maxMessagesPerTopic: {
value: 1000000,
validate: RED.validators.number()
},
interval: {
value: 1000,
validate: RED.validators.number()
},
dropOverflowMessages: {
value: false
}
},
color: "rgb(210, 220, 240)",
inputs: 1,
outputs: 1,
icon: "timer.png",
label: function() {
return this.name || "rate-limit";
},
labelStyle: function() {
return (this.name?"node_label_italic":"");
}
});
</script>