# How to pick a msg from a msg stream

**URL:** <https://discourse.nodered.org/t/how-to-pick-a-msg-from-a-msg-stream/75586>\
**Category:** General\
**Created:** [22 February 2023 13:44 UTC](https://discourse.nodered.org/t/how-to-pick-a-msg-from-a-msg-stream/75586 "2023-02-22T13:44:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bs-eng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bs-eng/32/51470_2.png) [@bs-eng](https://discourse.nodered.org/u/bs-eng)\
**Post date:** [22 February 2023 13:44 UTC](https://discourse.nodered.org/t/how-to-pick-a-msg-from-a-msg-stream/75586/1 "2023-02-22T13:44:22Z")

</div>

Hi there!  
I got the following scenario:

- sensor A is delivering continuously data by means of serial interface
- sensor B is delivering one trigger msg every once in a while (operator hits a button)

What I am trying to achieve is the following:  
At the moment the sensor B msg is received the next msg (or previous is ok too) of sensor A shall be picked. The data of both msg needs to be merged. The merged data of msgA and msgB are then handled in following nodes.

How can I do something like that in node-red?  
Thanks a lot!  
JR

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 February 2023 14:18 UTC](https://discourse.nodered.org/t/how-to-pick-a-msg-from-a-msg-stream/75586/2 "2023-02-22T14:18:02Z")

</div>

One way is with the contrib node [node-red-contrib-queue-gate](https://flows.nodered.org/node/node-red-contrib-queue-gate). Sensor B will trigger the release from the queue of the last message from Sensor A.

![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/2552f21fa1066839bd9c75c778632bef043e4321.jpeg)

```auto
[{"id":"b002bb26fe613d70","type":"inject","z":"a8b6a475c8d16c7d","name":"SENSOR A","props":[{"p":"payload"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":370,"y":300,"wires":[["a9610aec39003a2b"]]},{"id":"43c205f1871ca9fa","type":"inject","z":"a8b6a475c8d16c7d","name":"SENSOR B","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"trigger","payloadType":"str","x":370,"y":340,"wires":[["a9610aec39003a2b"]]},{"id":"a9610aec39003a2b","type":"q-gate","z":"a8b6a475c8d16c7d","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"peek","dropCmd":"drop","statusCmd":"status","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"storeName":"memory","x":530,"y":320,"wires":[["bc1885523c19002e"]]},{"id":"bc1885523c19002e","type":"debug","z":"a8b6a475c8d16c7d","name":"debug 265","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":320,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![bs-eng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bs-eng/32/51470_2.png) [@bs-eng](https://discourse.nodered.org/u/bs-eng)\
**Post date:** [22 February 2023 14:34 UTC](https://discourse.nodered.org/t/how-to-pick-a-msg-from-a-msg-stream/75586/3 "2023-02-22T14:34:12Z")

</div>

Wow, thank you so much! That works for me.  
Cheers  
JR

---

<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:** [8 March 2023 14:34 UTC](https://discourse.nodered.org/t/how-to-pick-a-msg-from-a-msg-stream/75586/4 "2023-03-08T14:34:23Z")

</div>

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