Suppose the Delay node is set to delay messages topic wise (Rate limit, msg.topic
instead of all messages). When a msg.reset
is sent with msg.topic
set, will the delay be cleared for that topic? I want to clear the delay/rate limit for only some of the topics that might have been set earlier.
msg.reset is a killer, it will reset the whole list of set timeout that is kept by the node.
Testing with code below will show you that the first three msgs will be dropped because of the msg.reset. The following two msgs will pass along in the flow.
msg = [
{payload:"Flow1",topic:"Flow1",delay:2000},
{payload:"Flow2",topic:"Flow2",delay:4000},
{payload:"Flow3",topic:"Flow3",delay:6000, reset:true},
{payload:"Flow4",topic:"Flow4",delay:10000},
{payload:"Flow5",topic:"Flow5",delay:2000},
];
return [msg];
Code:
[{"id":"cde7f17.e8a9f1","type":"tab","label":"Dealy node testing","disabled":false,"info":"Flow to test effect of msg.reset on the delay node"},{"id":"da87ef4c.51af1","type":"inject","z":"cde7f17.e8a9f1","name":"Start","topic":"Start","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":220,"wires":[["9c43852b.6c85d8"]]},{"id":"4b2dfa99.fbc6a4","type":"debug","z":"cde7f17.e8a9f1","name":"Final msg","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":700,"y":220,"wires":[]},{"id":"9c43852b.6c85d8","type":"function","z":"cde7f17.e8a9f1","name":"Testing payload","func":"msg = [\n {payload:\"Flow1\",topic:\"Flow1\",delay:2000},\n {payload:\"Flow2\",topic:\"Flow2\",delay:4000},\n {payload:\"Flow3\",topic:\"Flow3\",delay:6000, reset:true},\n {payload:\"Flow4\",topic:\"Flow4\",delay:10000},\n {payload:\"Flow5\",topic:\"Flow5\",delay:2000},\n ];\nreturn [msg];","outputs":1,"noerr":0,"x":300,"y":220,"wires":[["4327dd65.afd5b4","991311e9.36e5d"]]},{"id":"4327dd65.afd5b4","type":"delay","z":"cde7f17.e8a9f1","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":220,"wires":[["4b2dfa99.fbc6a4"]]},{"id":"991311e9.36e5d","type":"debug","z":"cde7f17.e8a9f1","name":"Debug delay","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"delay","x":470,"y":160,"wires":[]}]
If the topics are know in advance (and not too many) perhaps you can split the flow by topic and let each flow to be delayed by its own delay node ?
@chainhead You might want to take a look at node-red-contrib-msg-resend
. I think it can be configured to do what you want. Here is an example that cures the problem described by @Andrei.
[{"id":"f8c30900.d401e8","type":"msg-resend","z":"b9becc7d.405c38","interval":"1","intervalUnit":"secs","maximum":"1","bytopic":true,"clone":false,"firstDelayed":true,"addCounters":false,"highRate":true,"outputCountField":"","outputMaxField":"","name":"","x":550,"y":340,"wires":[["8e576fab.1d4608"]]},{"id":"8e576fab.1d4608","type":"debug","z":"b9becc7d.405c38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":710,"y":340,"wires":[]},{"id":"3e438eda.6608aa","type":"function","z":"b9becc7d.405c38","name":"msg-resend payload","func":"/*\nmsg = [\n {payload:\"Flow1\",topic:\"Flow1\",delay:2000},\n {payload:\"Flow2\",topic:\"Flow2\",delay:4000},\n {payload:\"Flow3\",topic:\"Flow3\",delay:6000, reset:true},\n {payload:\"Flow4\",topic:\"Flow4\",delay:10000},\n {payload:\"Flow5\",topic:\"Flow5\",delay:2000},\n ];\n*/\nmsg = [\n {payload:\"Flow1\",topic:\"Flow1\",resend_interval:2},\n {payload:\"Flow2\",topic:\"Flow2\",resend_interval:4},\n {payload:\"Flow3\",topic:\"Flow3\",resend_interval:6,resend_ignore:true},\n {payload:\"Flow4\",topic:\"Flow4\",resend_interval:10},\n {payload:\"Flow5\",topic:\"Flow5\",resend_interval:2},\n ];\n\n\n\nreturn [msg];","outputs":1,"noerr":0,"x":340,"y":340,"wires":[["f8c30900.d401e8"]]},{"id":"3d699b16.75dec4","type":"inject","z":"b9becc7d.405c38","name":"start msg-resend","topic":"start msg-resend","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":340,"wires":[["3e438eda.6608aa"]]}]
The reset function is not obvious. A message with resend_ignore=true
will cancel all delayed messages with the same topic.