Whilst the delay module has a function to limit rates, it buffers the unsent msg's and dispatches them in sequence according to the limit rate set.
This code (courtesy of Nick O'Leary) limits the msg flow similar to above, except it 'throws away' all of the intermediate msg's, instead of queuing them.
A further advantage is that you can set the limit rate to any value (within reason!) instead of being constrained to 1 sec,1 min, 1 hr.
The limit rate is set in the first line of code (in milliseconds).
Paul
Thanks for this! Was the only throttling/rate limiting one that almost did what I needed :)
Here's an improved version that allows overriding the interval, and groups rate limiting by topic (perfect say for an alert system, where you only want to hear each particular alert once per 20 minutes).
[{"id":"5b24df49.412f6","type":"function","z":"136ed48.14e8c2c","name":"Rate Limiter","func":"// Defaults to 10 minutes, overridable with msg.ratelimitms\n// Will limit per topic (including by null ones)\nvar interval = msg.ratelimitms || (1000*60*10); // minimum interval between messages (ms)\nvar key = \"lastTime\" + (msg.topic || \"null_topic\");\nvar lastReleased = context.get(key) || 0;\n\nvar now = Date.now();\n\nif (now-lastReleased > interval) {\n context.set(key,now);\n return msg;\n} else {\n return null;\n}","outputs":1,"noerr":0,"x":849.0173358917236,"y":438.0104217529297,"wires":[[]]}]