# I'm after (I think anyway) a rate limited gate

**URL:** https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615
**Category:** General
**Created:** [5 November 2023 09:18 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615 "2023-11-05T09:18:36Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 09:18 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/1 "2023-11-05T09:18:36Z")

</div>

So end result required  
Messages arrive and I want them rate limited (at least 1/sec) to give upstream nodes a chance to deal with them

But I want the messages to be gated, so that if upstream nodes take 2s - the next message isn't released until told to do so by a control message

Does my requirement make sense?

And has anyone already done something like this?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 09:21 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/2 "2023-11-05T09:21:43Z")

</div>

Hi @cymplecy,

Can I recommend a node I created to offer this kind of control?

its semaphore node, but with a dynamic fails safe?

> **[@marcus-j-davies/node-red-semaphore-plus](https://flows.nodered.org/node/@marcus-j-davies/node-red-semaphore-plus)**
>
> An advanced set of semaphore Nodes for Node RED, with a dynamic fail-safe

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 09:22 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/3 "2023-11-05T09:22:39Z")

</div>

Ta - I'll have a play

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 09:24 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/4 "2023-11-05T09:24:42Z")

</div>

From my own read me 👼

_This is a set of Nodes for Node RED, that allows messages to be queued, and signalled to pass, once a message has reached the end of the flow. But at the same time, allowing an optional fail-safe, that can be controlled dynamically._

_Furthermore, messages can be flagged to bypass the semaphore and 'sneak' past the messages waiting for the lock to be released._  
_This is achieved with either a single messge property, or a JSONata expression_.

Its not a limiter - more a node(s) to tightly control access to different parts off the flow

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 09:55 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/5 "2023-11-05T09:55:03Z")

</div>

This flow has just sat there for 30 mins while I went and made breakfast ☹

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4abe698cf948a5694533741dabddda242abe8e1d.png)

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 09:58 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/6 "2023-11-05T09:58:05Z")

</div>

The fail-safe is global.

it looks like you clicked this one first?  
and only released once?

 ![Screenshot 2023-11-05 at 09.57.00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abc5802e40f40dea5aea532d76a68f1e8fbc17da.png)

I should re-order the example flow 😅

Each message sets the current fail-safe, once it passes if that makes sense.

**LQ** - Local Queue  
**GQ** - Global Queue  
**LFS** - Last Fail Safe that was Set

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 10:03 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/7 "2023-11-05T10:03:51Z")

</div>

I'll go and make a cup of coffee and re-read that several times before replying further 🙂

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 10:11 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/8 "2023-11-05T10:11:06Z")

</div>

it looks like you done something like this..

x3  
x2 (should be x3) - as the 3rd message, would have it to disable the fail safe  
x2

![Nov-05-2023 10-08-05](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9b5bf26b2dc45f106d88338e3bfea0839e057d1.gif)

The last message to pass (allow through) is the message that sets the current active fail-safe  
the 3rd message inject at the top set it to disabled

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 10:22 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/9 "2023-11-05T10:22:13Z")

</div>

Yes- that's what I did 🙂

What's all this local queue, global queue?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 10:27 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/10 "2023-11-05T10:27:21Z")

</div>

The whole engine works with a global queue - where each `take` contributes to that queue.

but at the same - the `take`s of course know what they, them self have waiting.

So the status' are just showing you the state of the engine

`QG` - The Queue size for all `Take`s  
`LQ` - The Queue size for this `Take`  
`LFS` - The fail-safe time currently enforced (globally)

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 10:28 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/11 "2023-11-05T10:28:46Z")

</div>

Ok 🙂  
I'll try actually using it with my MQTT project and see how it goes 🙂

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 10:29 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/12 "2023-11-05T10:29:59Z")

</div>

![Screenshot 2023-11-05 at 10.29.06](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/9120fdb63de56e4ef0a0011caba294ed0bc1eb13.png)

2 x`LQ` (5+4) = `GQ` = 9

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 10:32 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/13 "2023-11-05T10:32:53Z")

</div>

Got it 🙂

Why is there a config? Does this mean I can have independent flows with their own global queues?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 10:34 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/14 "2023-11-05T10:34:37Z")

</div>

Correct!

As the nodes share an engine, it needs a config for it (it manages the queue side of it all)  
so you can have 2 independent globe queues (just set them in the node that belong to that global queue)

The idea with the `FS Reset` node  
if you set the fail-safe to say 5s, then if a message taking longer then 5s (say 4s) , you can extend (if you want) that current fail-safe to say 10s - meaning the next message will wait 10s (instead of 5s)

then once the 10s message passes, it will again set it to 5s - unless you extend again  
that is the dynamic side of the fail-safe 😄

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [5 November 2023 10:42 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/15 "2023-11-05T10:42:07Z")

</div>

Hi cymplecy,  
I know you prefer to use standard nodes if at all possible.  
Just to note you can use the delay node in rate limit, and msg.flush 1 to release next message.  
So set rate limit to high value say 60 second  
once up stream nodes have finish feed msg.flush = 1 back to the rate limit node, making sure there are no other msg properties in the message.  
There are several examples of this on the forum [How to create a sequence to send msg one after another instead in parallel - #4 by E1cid](https://discourse.nodered.org/t/how-to-create-a-sequence-to-send-msg-one-after-another-instead-in-parallel/70363/4)

---

<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: [5 November 2023 10:42 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/16 "2023-11-05T10:42:48Z")

</div>

> [@cymplecy](#):
>
> I'll try actually using it with my MQTT project and see how it goes

Can you explain in a bit more detail exactly what the purpose is? I suspect there may be a better way.

> [@cymplecy](#):
>
> I want them rate limited (at least 1/sec) to give upstream nodes a chance to deal with them

Should that be downstream (ie later) nodes?

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 10:48 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/17 "2023-11-05T10:48:14Z")

</div>

Can I clear the queue?

@E1cid @colin I'll circle back round if this semaphore thing gets too complex 🙂 And yes - I meant down-stream 🙂

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 10:51 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/18 "2023-11-05T10:51:14Z")

</div>

Not presently ☹  
the only way is to trigger the release a few times  
messages are released with `msg.smp_isFailsafe` which denotes if they are released due to the FS being triggered (not sure it helps though)

But I think @Colin suggested that also when I was building it (I should really add it)

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [5 November 2023 10:57 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/19 "2023-11-05T10:57:55Z")

</div>

> [@marcus-j-davies](#):
>
> Not presently

☹ shame - it's making testing a bit tricky

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [5 November 2023 10:59 UTC](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615/20 "2023-11-05T10:59:18Z")

</div>

Re-naming the global queue, should reset it however (but that's just a dirty way of clearing it)

I'll add a clear control message today once a I get 5 - not to win you ever of course 😄 - but more I should really add that in

[Next page](https://discourse.nodered.org/t/im-after-i-think-anyway-a-rate-limited-gate/82615.md?page=2)
