# Topic-wise delay in Delay node?

**URL:** <https://discourse.nodered.org/t/topic-wise-delay-in-delay-node/1856>\
**Category:** Feature Requests\
**Created:** [27 July 2018 09:53 UTC](https://discourse.nodered.org/t/topic-wise-delay-in-delay-node/1856 "2018-07-27T09:53:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chainhead](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chainhead/32/40800_2.png) [@chainhead](https://discourse.nodered.org/u/chainhead)\
**Post date:** [27 July 2018 09:53 UTC](https://discourse.nodered.org/t/topic-wise-delay-in-delay-node/1856/1 "2018-07-27T09:53:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [27 July 2018 13:23 UTC](https://discourse.nodered.org/t/topic-wise-delay-in-delay-node/1856/2 "2018-07-27T13:23:48Z")

</div>

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.

```auto
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:

```auto
[{"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 ?

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [28 July 2018 19:55 UTC](https://discourse.nodered.org/t/topic-wise-delay-in-delay-node/1856/3 "2018-07-28T19:55:58Z")

</div>

@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.

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![chainhead](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chainhead/32/40800_2.png) [@chainhead](https://discourse.nodered.org/u/chainhead)\
**Post date:** [31 July 2018 09:38 UTC](https://discourse.nodered.org/t/topic-wise-delay-in-delay-node/1856/4 "2018-07-31T09:38:37Z")

</div>

@drmibell Will check, thanks.

@Andrei unfortunately, the number of topics will not be known in advance.
