# Force One Message at a Time?

**URL:** <https://discourse.nodered.org/t/force-one-message-at-a-time/62859>\
**Category:** General\
**Created:** [19 May 2022 18:02 UTC](https://discourse.nodered.org/t/force-one-message-at-a-time/62859 "2022-05-19T18:02:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![efaden](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/efaden/32/61856_2.png) [@efaden](https://discourse.nodered.org/u/efaden)\
**Post date:** [19 May 2022 18:02 UTC](https://discourse.nodered.org/t/force-one-message-at-a-time/62859/1 "2022-05-19T18:02:28Z")

</div>

I'm looking for a way to only allow a single message to be processed at a time through a block of my flow. I'd like to use a queue to queue the rest. Was going to use q-gate, but it's missing one feature. If the queue runs empty I'd like to automatically open the queue. q-gate doesn't seem to have a way to do that. Basically when I get to the end of a run either de-queue the next item or if the queue is empty, just go to the open state. e.g. automatically de-queue if it gets another message while i'm not processing. Anyone know a simple way?

---

<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:** [19 May 2022 21:02 UTC](https://discourse.nodered.org/t/force-one-message-at-a-time/62859/2 "2022-05-19T21:02:23Z")

</div>

What I think you need is the `delay` node.

Put that in and then _open_ it (edit it)

Then select `rate limit`

![Screenshot from 2022-05-20 07-01-10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/909aa490440c067459024ae87a9caae311543cac.png)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [19 May 2022 21:25 UTC](https://discourse.nodered.org/t/force-one-message-at-a-time/62859/3 "2022-05-19T21:25:52Z")

</div>

Hello, and welcome to node-red!

Take a look at the brilliantly simple [node-red-contrib-semaphore](https://flows.nodered.org/node/node-red-contrib-semaphore)

It's just a pair of nodes that lets your flow `take` a "ticket" from a configurable pool of tickets _(in your case it's just the 1)_, and some time later your flow can "leave" that ticket, which immediately makes it available for the next msg in line to take it. Every msg that reaches the `semaphore-take` node **after the pool is empty** gets queued up until a semaphore becomes available by another msg reaching the `semaphore-leave` node.

The only thing to watch for is that you never want to take a semaphore without later returning it -- or else your queued up msgs will never be released. Best practice is to put a `watch` node on any nodes between the semaphores, to catch exceptions (e.g. an `http-request` that fails).

I can probably dig up an example of a flow that limits how many msgs can be "in-flight", if you get stuck trying to set it up -- but it's pretty simple to use. Good luck!

---

<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:** [18 July 2022 21:26 UTC](https://discourse.nodered.org/t/force-one-message-at-a-time/62859/4 "2022-07-18T21:26:27Z")

</div>

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