# Help with message queuing (maybe a repeat)

**URL:** <https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134>\
**Category:** General\
**Created:** [12 August 2024 21:05 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134 "2024-08-12T21:05:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2024 21:05 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/1 "2024-08-12T21:05:45Z")

</div>

I went back through my history to check and couldn't find anything, so this is a post asking for help with messages.

I've got into voice messages and not allowing them all to play at once is a challenge.

I have a `gate` (foreign) node set to queue.  
It gets tricky but most of the time it works.

## What is happening - better discription:

_Here goes:_  
A messages is _received_.  
It is queued.  
A `status` node parses the message from the `gate` node and if there is only `1` message it triggers a `next message` message to be sent to the `gate` (more more so `queue`) node.  
This then sends the message on to the TTS node.  
When that is done - and all is good - it too sends a `next message` back to the `queue` node so if there is another message, it is sent.

## The problem is that it is:

If - while the message is being _handled_ by the code AFTER the `queue` node the problem happens.

As it is no messages in it's queue, the `status` node and associated stuff don't see any messages and so this next/new message is then onsent and it _steps on_ the previous message.

I'm hoping _Sod's law_ steps in and after my posting, I work out a solution.

And saying that, I may have now thought of the solution.

This is a **BASIC** overview of the structure.

 ![Screenshot from 2024-08-13 07-03-04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/4/44d30acf758b2a2622b6430c718fe873de966852.png)

My thought is to move the wire coming back (indicating all good and send next message) from the `queue` node to the `message queue counter` node.

---

<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:** [12 August 2024 21:30 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/2 "2024-08-12T21:30:47Z")

</div>

This is the standard flow for sequential operations, using a Delay node with its Flush capability. Open the Comment node to see more details of how to use it.

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

```auto
[{"id":"b6630ded2db7d680","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":480,"wires":[["ed63ee4225312b40"]]},{"id":"ed63ee4225312b40","type":"delay","z":"bdd7be38.d3b55","name":"Queue","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":310,"y":480,"wires":[["d4d479e614e82a49","7eb760e019b512dc"]]},{"id":"a82c03c3d34f683c","type":"delay","z":"bdd7be38.d3b55","name":"Some more stuff to do","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":800,"y":480,"wires":[["7c6253e5d34769ac","b23cea1074943d4d"]]},{"id":"2128a855234c1016","type":"link in","z":"bdd7be38.d3b55","name":"link in 1","links":["7c6253e5d34769ac"],"x":95,"y":560,"wires":[["3a9faf0a95b4a9bb"]]},{"id":"7c6253e5d34769ac","type":"link out","z":"bdd7be38.d3b55","name":"link out 1","mode":"link","links":["2128a855234c1016"],"x":665,"y":560,"wires":[]},{"id":"b23cea1074943d4d","type":"debug","z":"bdd7be38.d3b55","name":"OUT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":400,"wires":[]},{"id":"d4d479e614e82a49","type":"debug","z":"bdd7be38.d3b55","name":"IN","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":400,"wires":[]},{"id":"3a9faf0a95b4a9bb","type":"function","z":"bdd7be38.d3b55","name":"Flush","func":"return {flush: 1}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":190,"y":560,"wires":[["ed63ee4225312b40"]]},{"id":"7eb760e019b512dc","type":"function","z":"bdd7be38.d3b55","name":"Some functions to be performed","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":480,"wires":[["a82c03c3d34f683c"]]},{"id":"e35f37deeae94860","type":"comment","z":"bdd7be38.d3b55","name":"Set the queue timeout to larger than you ever expect the process to take","info":"This is a simple flow which allows a sequence of nodes to be \nprotected so that only one message is allowed in at a time. \nIt uses a Delay node in Rate Limit mode to queue them, but \nreleases them, using the Flush mechanism, as soon as the \nprevious one is complete. Set the timeout in the delay node to \na value greater than the maximum time you expect it ever to take. \nIf for some reason the flow locks up (a message fails to indicate \ncompletion) then the next message will be released after that time.\n\nMake sure that you trap any errors and feed back to the Flush \nnode when you have handled the error. Also make sure only one \nmessage is fed back for each one in, even in the case of errors.","x":270,"y":360,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 August 2024 21:35 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/3 "2024-08-12T21:35:56Z")

</div>

Thanks.

That looks familiar.... (_As I said, I've probably asked this but couldn't find the thread_)

I've stored that in my _archive_ for future reference too.

There is a catch, that the processing time on the messages is unknown as they can range in size/length/time from short to ...... LONG.

But I guess I just set the timeout to LONG+ 😉

---

<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:** [13 August 2024 07:31 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/4 "2024-08-13T07:31:03Z")

</div>

What do you mean by LONG+?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 August 2024 20:47 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/5 "2024-08-13T20:47:01Z")

</div>

Well, I'm not sure. I will have to see what happens with what I have set now and if they start to overlap, I'll increase it.

And sorry for marking the wrong post as the solution.  
I've now changed it to your post.

---

<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:** [13 August 2024 21:07 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/6 "2024-08-13T21:07:50Z")

</div>

I meant do you mean minutes long or hours?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 August 2024 21:10 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/7 "2024-08-13T21:10:40Z")

</div>

No.

I was also being .... (how do you spell it?) facetious?  
(sarcastic?)

No, probably more minutes.

---

<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:** [27 August 2024 21:11 UTC](https://discourse.nodered.org/t/help-with-message-queuing-maybe-a-repeat/90134/8 "2024-08-27T21:11:25Z")

</div>

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