# Delay node, with rate limit: how to check if every single message reached "the end" of the flow

**URL:** https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687
**Category:** General
**Created:** [4 July 2022 15:02 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687 "2022-07-04T15:02:19Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)
#### Post date: [4 July 2022 15:02 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/1 "2022-07-04T15:02:19Z")

</div>

Hi all,  
it's very hard for me to ask this question because I understand that's a really complex scenario.

But... let's try.

I've got a split & delay with rate limit that sends every 10sec. a message.

For each message I need (and I can't do that in a different way) to call an API, then do a little process and so on.

My problem is that, obviously, API call is asyncronous and so I've got a different amount of time at response.. Sometimes this thime is bigger tha 10 seconds, so the the next message is passed.

That's not a problem, if not I'll need to be sure tha every single message is processed.  
So i checked msg.parts to check when the loop arrives to the end but, for the previous reason, it could happen that a message is not processed "in time" and the flow pass over to next parts, _without doing the correct elaboration_.

So my question is: how to check at every iteration if ALL MESSAGES are be processed?

Thank you all.

---

<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: [4 July 2022 15:23 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/2 "2022-07-04T15:23:41Z")

</div>

Do you mean that, ideally, you want to not release the next message until the previous one has completed? If so then the current beta version of node red (v3.0 beta 4) has a fix to the delay node that allows you to feedback when the flow has completed to release the next one from the delay node. See [Wait for payload to finish flow before passing another payload - #33 by Colin](https://discourse.nodered.org/t/wait-for-payload-to-finish-flow-before-passing-another-payload/64171/33) for a flow that works in the beta version (it didn't at the time of the post). Set the delay node to rate limit with a large timeout so it only releases messages if a message gets lost. Otherwise the next one will be released as soon as the previous one says it is complete. Note that the message sent back must be an empty message except for msg.flush.

---

<div class="post-metadata">

### Author: ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)
#### Post date: [4 July 2022 15:34 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/3 "2022-07-04T15:34:24Z")

</div>

Hi Colin,  
yes this way could be a solution.

For me it could be better something that I can check at a specific position of the flow (i.e. with a switch). At the moment, for example, I check something like that:

```auto
if (msg.parts.count === (msg.parts.index+1)) {
    node.warn("ESCO")
    msg.exitFlow = true;
}
return msg;

```

The problem is that I could reach the "last element" but some previuos message could be not processed (because of async calls).

---

<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: [4 July 2022 15:35 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/4 "2022-07-04T15:35:47Z")

</div>

> [@hammeronthenet](#):
>
> For me it could be better something that I can check at a specific position of the flow

Check what?

---

<div class="post-metadata">

### Author: ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)
#### Post date: [4 July 2022 15:36 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/5 "2022-07-04T15:36:35Z")

</div>

Look at my code example.  
Something like "x messages of y processed".

---

<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: [4 July 2022 15:40 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/6 "2022-07-04T15:40:21Z")

</div>

That sounds horribly complicated, do you really need that? I can't immediately see an easy way to achieve it.

---

<div class="post-metadata">

### Author: ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)
#### Post date: [4 July 2022 15:47 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/7 "2022-07-04T15:47:39Z")

</div>

Yes, sadly I need that.

I was thinkink to use node-red-contrib-loop to do the same thing with more control.

It could be a solution, but for that I need to completely change my flow.

At the moment this could be the best solution imho.

---

<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: [4 July 2022 16:28 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/8 "2022-07-04T16:28:59Z")

</div>

> [@hammeronthenet](#):
>
> Yes, sadly I need that.

Why do you need that?

---

<div class="post-metadata">

### Author: ![hammeronthenet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hammeronthenet/32/29102_2.png) [@hammeronthenet](https://discourse.nodered.org/u/hammeronthenet)
#### Post date: [5 July 2022 06:58 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/9 "2022-07-05T06:58:32Z")

</div>

It's complicated to explain, but I need to call an API to read some ata related to the message and then call others two APIs that wrote foundamentally write changes on a database (I can't change the backend logic, if not it was okay).

So I need that every message calls the 3 APIs before "exit" the loop and continue with the rest of the flow.

I'm unable to resume that better, sorry. 🙂

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [5 July 2022 07:15 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/10 "2022-07-05T07:15:51Z")

</div>

I believe there was also a discussion last week about the semaphore node (in the same discussion about modifying the delay node if i recall)

Possibly the sempahore node would be better/give you more control

From what you seem to say

1. A message comes in - you then need to use the contents of that message to call an API, once that API returns you need to call another two APIs

2. Process the next message (that may have arrived before 1) has finished - so you need to queue them until you get to them

Question: - How do you handle it if any of the API calls fail - what is then meant to happen ?  
Are the messages still in the queue valid at that point or do they need to be flushed ?

It also appears that [GitHub - drmibell/node-red-contrib-queue-gate: A Node-RED node for controlling message flow (with queueing).](https://github.com/drmibell/node-red-contrib-queue-gate)

Would give you all the capabilities you require

Craig

---

<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 July 2022 07:52 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/11 "2022-07-05T07:52:30Z")

</div>

So what is wrong with using the delay node as I suggested, or semaphore nodes to achieve the same thing? If it is that you want to run the three APIs in parallel to increase the throughput then put a delay node loop around each one, which will stop messages overtaking each other as they go through.

---

<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 July 2022 07:56 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/12 "2022-07-05T07:56:12Z")

</div>

> [@craigcurtin](#):
>
> It also appears that [GitHub - drmibell/node-red-contrib-queue-gate: A Node-RED node for controlling message flow (with queueing).](https://github.com/drmibell/node-red-contrib-queue-gate)

Unfortunately it is not simple (maybe not possible) to use that node for this purpose, even though it was intended to be used in that way. I was unable to construct a simple flow using it that did not suffer from problems due to race conditions, when messages arrived at the front at inopportune moments.

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [5 July 2022 22:52 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/13 "2022-07-05T22:52:18Z")

</div>

> [@Colin](#):
>
> Unfortunately it is not simple (maybe not possible) to use that node for this purpose, even though it was intended to be used in that way. I was unable to construct a simple flow using it that did not suffer from problems due to race conditions, when messages arrived at the front at inopportune moments.

So is there a problem with the node (as it sounded perfect for this role) or the OPs requirements are weird and not inline with how it was envisaged to work ?

Craig

---

<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: [6 July 2022 06:16 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/14 "2022-07-06T06:16:00Z")

</div>

There isn't a problem with the node, in the sense that it does do what the docs say it should do.  
The problem using it for the situation here relates, if I remember correctly, to handling the situation where a new message comes in the front just after the previous one has been has been completed. At that stage I couldn't see an obvious enhancement to the node that would solve the problem.

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [6 July 2022 06:19 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/15 "2022-07-06T06:19:06Z")

</div>

Aah - from my quick reading it seemed there was queue management available within the node - i assumed this would allow you to tell the queue when processing had finished and to release the next queued message.

@drmibell - could you comment on this as Colin has a lot more knowledge than me and this appears to be your baby ?

Craig

---

<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: [4 September 2022 06:20 UTC](https://discourse.nodered.org/t/delay-node-with-rate-limit-how-to-check-if-every-single-message-reached-the-end-of-the-flow/64687/16 "2022-09-04T06:20:03Z")

</div>

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