FIFO

FIFO - First in first out subflow

This flow receives a series of msg.payloads and builds a queue using FIFO (First in First out) method. The LIFO size is configurable through subflow environment variables.

This subflow was created by Smart-Tech as part of the ST-One project.

Inputs

msg.topic == put Will add the msg.payload to the end of the array. Every time a new item is received the second output sends the complete queue.

msg.topic == get Will remove the first item of the stack and will send it in the first output

msg.topic == list Sends the complete list on the second output.

Outputs

##$ Output 1 The first item on the top of the stack. It is sent only when msg.topic == get.

Output 2

The complete queue in Array format. It is sent every time a new item is added, removed or when msg.topic == list

Status

Always show the queue size.

Environment Variables

Buffer_Size defines the size of the queue. If a new item arrives and the queue is full, the oldest item will be removed.

[{"id":"888786c5.d5aab8","type":"subflow","name":"FIFO","info":"# FIFO\n## First in First Out subflow\nThis flow receives a series of msg.payloads and builds a queue using FIFO (First in First out) method. The LIFO size is configurabe through subflow enviroment variables.\n\n### Input\n`msg.topic == put`\nWill add the `msg.payload` to the end of the array. Everytime a new item is received the second output sends the complete queue.\n\n`msg.topic == get`\nWill remove the first item of the stack and will send it in the first output\n\n`msg.topic == list`\nSends the complete list on the second output.\n\n### Output 1\nThe first item on the top of the stack. It is sent only when `msg.topic == get`.\n\n### Output 2\nThe complete queue in Array format. It is sent everytime a new item is added, removed or when `msg.topic == list`\n\n### Status\nAlways show the queue size.\n\n### Enviroment Variables\n`Buffer_Size` defines the size of the queue. If a new item arrives and the queue is full, the oldest item will be removed.","category":"","in":[{"x":140,"y":120,"wires":[{"id":"5ce94b12.5c1c44"}]}],"out":[{"x":720,"y":60,"wires":[{"id":"a6ca9e09.83012","port":0}]},{"x":900,"y":100,"wires":[{"id":"d22ee914.d446d8","port":0}]}],"env":[{"name":"Buffer_Size","type":"num","value":"6"}],"icon":"font-awesome/fa-ellipsis-v","status":{"x":1040,"y":140,"wires":[{"id":"ad0059b4.1b2978","port":0}]}},{"id":"5ce94b12.5c1c44","type":"switch","z":"888786c5.d5aab8","name":"Topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"get","vt":"str"},{"t":"eq","v":"put","vt":"str"},{"t":"eq","v":"list","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":270,"y":120,"wires":[["a6ca9e09.83012"],["feb761ec.4c293"],["d22ee914.d446d8"],["d22ee914.d446d8"]]},{"id":"feb761ec.4c293","type":"function","z":"888786c5.d5aab8","name":"put","func":"var queue = flow.get(\"queue\")\n\n\nif (!Array.isArray(queue)){\n    queue = [];\n}else if ( queue.length >= env.get(\"Buffer_Size\") ){\n    queue.pop(1);\n}\n\nqueue.unshift(msg.payload);\n\nflow.set(\"queue\", queue);\nmsg.payload = queue;\n\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":100,"wires":[["d22ee914.d446d8"]]},{"id":"a6ca9e09.83012","type":"function","z":"888786c5.d5aab8","name":"get","func":"var queue = flow.get(\"queue\")\nvar item;\n\nif (!Array.isArray(queue)){\n    queue = [];\n}else{\n    item = queue.pop(1);\n}\n\n\nflow.set(\"queue\", queue)\nmsg.payload = item;\n\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":60,"wires":[["d22ee914.d446d8"]]},{"id":"d22ee914.d446d8","type":"change","z":"888786c5.d5aab8","name":"list","rules":[{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":140,"wires":[["ad0059b4.1b2978"]]},{"id":"ad0059b4.1b2978","type":"change","z":"888786c5.d5aab8","name":"Count","rules":[{"t":"set","p":"payload","pt":"msg","to":"$count(msg.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":140,"wires":[[]]},{"id":"8b31439b.c3a39","type":"subflow:888786c5.d5aab8","z":"ab14b933.6f7428","name":"","env":[{"name":"","type":"str","value":""}],"x":520,"y":440,"wires":[["30e4114b.c20f4e"],["85fb2bb8.9cf518"]]}]

Flow Info

Created 5 years, 3 months ago
Updated 4 years, 10 months ago
Rating: 5 2

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • function (x2)
  • switch (x1)
Other
  • subflow (x1)
  • subflow:888786c5.d5aab8 (x1)

Tags

  • FIFO
  • queue
  • Buffer
  • ST-One
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option