Delay node rate limit by topic starts limiting

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

Thanks!

[{"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"]]}]

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


and each one set like this:
Screenshot 2024-01-24 at 4.31.52 AM

[{"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"]]}]

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

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

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

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.

Thanks @dceejay,

I've replied in the GH issue :slight_smile:

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

Edit:
Configure it like this

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.

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