# Delay node rate limit by topic starts limiting

**URL:** <https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857>\
**Category:** General\
**Tags:** delay\
**Created:** [24 January 2024 00:23 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857 "2024-01-24T00:23:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![afonsoc12](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afonsoc12/32/87607_2.png) [@afonsoc12](https://discourse.nodered.org/u/afonsoc12)\
**Post date:** [24 January 2024 00:23 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/1 "2024-01-24T00:23:52Z")

</div>

Hi,  
So I want to rate limit the amount of output messages, by topics.  
I have a node that fires messages with different msg.topics and msg.payload, which is exemplified with inject nodes in the photo.

The idea is:

- There will be messages for multiple topics being created every 30 seconds.
- For each topic, no more than 1 message should flow for the specified rate limit. However, all messages for other topics should flow normally (if the first in the limit specified, counted by topic).

In the example, if inject a message from topic1 and topic2 at the same time, I would expect them to flow through since it's the first time they appear. However, they are being queued for 15 secs. Why is that? Shouldn't it start right away?

It looks like the node is only available after 15 seconds, the rate limit time

 ![Screenshot 2024-01-24 at 00.21.50](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/867dd1b8a4a7d358b8479c02902e79ea773d4997.png)

Thanks!

```auto
[{"id":"802deb2b30bb1599","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"5b3fbbaa5a4caca5","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic1","payload":"a","payloadType":"str","x":220,"y":180,"wires":[["07ff0366f2330fcc"]]},{"id":"8706ae1254fec722","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic1","payload":"b","payloadType":"str","x":226,"y":232,"wires":[["07ff0366f2330fcc"]]},{"id":"fd4457480abf88b6","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic2","payload":"c","payloadType":"str","x":226,"y":312,"wires":[["07ff0366f2330fcc"]]},{"id":"af5f1a9ead9367af","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic2","payload":"d","payloadType":"str","x":232,"y":364,"wires":[["07ff0366f2330fcc"]]},{"id":"60193aff98e25bab","type":"debug","z":"802deb2b30bb1599","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":300,"wires":[]},{"id":"07ff0366f2330fcc","type":"delay","z":"802deb2b30bb1599","name":"","pauseType":"queue","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":480,"y":260,"wires":[["60193aff98e25bab"]]}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 January 2024 09:15 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/2 "2024-01-24T09:15:24Z")

</div>

To be clear, if you send A,B,A,B,C,D you should see A,B,C,D and 30 seconds later C,D

Is that right? If so I think you need to have a delay per topic like this

 ![Screenshot 2024-01-24 at 4.31.44 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/286d926b04ce1cab85235805193223bbdcf2aca8.png)  
and each one set like this:  
 ![Screenshot 2024-01-24 at 4.31.52 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad028f8bb257bc6481384917a2709995d5e65d4b.png)

```auto
[{"id":"5b3fbbaa5a4caca5","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic1","payload":"a","payloadType":"str","x":220,"y":180,"wires":[["a8cef045b1ec6af2"]]},{"id":"8706ae1254fec722","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic1","payload":"b","payloadType":"str","x":220,"y":240,"wires":[["509275ed0dc64519"]]},{"id":"fd4457480abf88b6","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic2","payload":"c","payloadType":"str","x":230,"y":300,"wires":[["068eed7d45c1dc5e"]]},{"id":"af5f1a9ead9367af","type":"inject","z":"802deb2b30bb1599","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic2","payload":"d","payloadType":"str","x":220,"y":360,"wires":[["a17991a98df39a83"]]},{"id":"60193aff98e25bab","type":"debug","z":"802deb2b30bb1599","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":920,"y":260,"wires":[]},{"id":"a8cef045b1ec6af2","type":"delay","z":"802deb2b30bb1599","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":480,"y":180,"wires":[["60193aff98e25bab"]]},{"id":"509275ed0dc64519","type":"delay","z":"802deb2b30bb1599","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":480,"y":240,"wires":[["60193aff98e25bab"]]},{"id":"a17991a98df39a83","type":"delay","z":"802deb2b30bb1599","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":480,"y":360,"wires":[["60193aff98e25bab"]]},{"id":"068eed7d45c1dc5e","type":"delay","z":"802deb2b30bb1599","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":480,"y":300,"wires":[["60193aff98e25bab"]]}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [24 January 2024 10:38 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/3 "2024-01-24T10:38:26Z")

</div>

It is currently working as designed - see [Delay node behavior for all messages and for each msg.topic inconsistent · Issue #4524 · node-red/node-red · GitHub](https://github.com/node-red/node-red/issues/4524).  
The design was to ensure each topic gets a fair use of a release queue, and to store up as many different topics as possible before sending.

---

<div class="post-metadata">

**Author:** ![afonsoc12](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afonsoc12/32/87607_2.png) [@afonsoc12](https://discourse.nodered.org/u/afonsoc12)\
**Post date:** [24 January 2024 21:16 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/4 "2024-01-24T21:16:26Z")

</div>

Thank you for your reply.

I'm rate limit by topic, i.e., I want to rate limit based on the topic, so if you send two messages with different msg.topic, they should both appear

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 January 2024 21:21 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/5 "2024-01-24T21:21:57Z")

</div>

Is there a reason you can’t do as I suggested? I couldn’t get what you wanted using just one delay node

---

<div class="post-metadata">

**Author:** ![afonsoc12](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afonsoc12/32/87607_2.png) [@afonsoc12](https://discourse.nodered.org/u/afonsoc12)\
**Post date:** [24 January 2024 21:28 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/6 "2024-01-24T21:28:16Z")

</div>

That was just a toy example.

In reality, I have an entity that reads all temperature sensors around the house (each sensor is a topic) and notifies if temperature greater or smaller than thresholds. These report every 30 seconds, but I only want to be notified once every 3h if the temperature maintains. However, if the temperature in the kitchen increases and 5 mins after so does the living room, I want to be notified for both (independent topics).

What happens currently is that during the first 3h after a deployment, it doesn't pass any messages which is a bit inconvenient.

---

<div class="post-metadata">

**Author:** ![afonsoc12](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afonsoc12/32/87607_2.png) [@afonsoc12](https://discourse.nodered.org/u/afonsoc12)\
**Post date:** [24 January 2024 21:29 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/7 "2024-01-24T21:29:08Z")

</div>

Thanks @dceejay,

I've replied in the GH issue 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 January 2024 13:35 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/8 "2024-01-25T13:35:17Z")

</div>

I believe that you can do that with a Trigger node.

Edit:  
Configure it like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58302408dcb636a77a1d11a225c7041a9d95d16c.png)

Send it just the 'bad' messages. When the first is sent it will pass it on, but will then ignore any messages with that topic for the next three hours.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 February 2024 13:35 UTC](https://discourse.nodered.org/t/delay-node-rate-limit-by-topic-starts-limiting/84857/9 "2024-02-08T13:35:44Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
