Priority-Queue

DESCRIPTION: This subflow splits the messages into 3 categories. First category path has the highest priority, second has the second priority, third has the least... This node's use is better understood with highly busy flows, where lots of messages are passing through the flow. Some people might want to send some of these messages before the others by giving them msg.priority variables. By setting these values you make sure that without dealing with the first priority messages the flow doesn't deal with the others.

prioqueue_general

DETAILS:

  • This flow has a simple logic. There are 3 gates which hold the message if necessary. Gate one always sends the message comes to it. Gate two sends the messages it holds if gate one is not busy and finished its work, in other words waits for gate one. Gate three waits for both of them.

  • User can set msg.priority to one of the [1,2,3] given numbers. Or set the flows variables to their liking

Here is the logic that controls the gates:

prioqueue_function

OUTPUTS:

  • First output sends the top priority messages.
  • Second output sends the second priority messages.
  • Third output sends the third priority messages.
[{"id":"5caaf3ef1750712d","type":"subflow","name":"Subflow 11","info":"","category":"","in":[{"x":40,"y":200,"wires":[{"id":"2441d7b0c195b6b2"}]}],"out":[{"x":1260,"y":80,"wires":[{"id":"19ed5b2a123f0de8","port":0}]},{"x":1260,"y":200,"wires":[{"id":"fd6b6e8e73d17fd7","port":0}]},{"x":1260,"y":320,"wires":[{"id":"4bb7268a5a5095b9","port":0}]}],"env":[{"name":"priorityOneIdentifier","type":"num","value":"1"},{"name":"priorityTwoIdentifier","type":"num","value":"2"},{"name":"priorityThreeIdentifier","type":"num","value":"3"}],"meta":{},"color":"#DDAA99"},{"id":"19ed5b2a123f0de8","type":"q-gate","z":"5caaf3ef1750712d","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":"100","keepNewest":false,"qToggle":false,"persist":false,"storeName":"memory","x":970,"y":80,"wires":[[]]},{"id":"fd6b6e8e73d17fd7","type":"q-gate","z":"5caaf3ef1750712d","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":"100","keepNewest":false,"qToggle":false,"persist":false,"storeName":"memory","x":970,"y":200,"wires":[[]]},{"id":"4bb7268a5a5095b9","type":"q-gate","z":"5caaf3ef1750712d","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":"100","keepNewest":false,"qToggle":false,"persist":false,"storeName":"memory","x":970,"y":320,"wires":[[]]},{"id":"07bf8a66b718d8e8","type":"function","z":"5caaf3ef1750712d","name":"","func":"msg.topic = \"control\";\nmsg.payload = \"flush\";\nlet msg1;\nlet msg2;\nlet msg3;\n\nif(msg.status.text !== \"queuing: 0\" && msg.id === 1) {\n    msg1 = msg;\n} else if (msg.status.text !== \"queuing: 0\" && msg.id === 2) {\n    msg2 = msg;\n} else if (msg.status.text !== \"queuing: 0\" && msg.id === 3) {\n    msg3 = msg;\n}\n\nreturn [msg1, msg2, msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":380,"wires":[["19ed5b2a123f0de8"],["fd6b6e8e73d17fd7"],["4bb7268a5a5095b9"]]},{"id":"e2b1931fa7499729","type":"function","z":"5caaf3ef1750712d","name":"","func":"let msg1;\nlet msg2;\nlet msg3;\n\nif(msg.priority === msg.priorityOne){\n    msg1 = msg;\n} else if(msg.priority === msg.priorityTwo){\n    msg2 = msg;\n} else if(msg.priority === msg.priorityThree){\n    msg3 = msg;\n}\n\nreturn [msg1, msg2, msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":200,"wires":[["19ed5b2a123f0de8"],["fd6b6e8e73d17fd7"],["4bb7268a5a5095b9"]]},{"id":"d1cd4c735eb34df0","type":"status","z":"5caaf3ef1750712d","name":"","scope":["19ed5b2a123f0de8"],"x":180,"y":300,"wires":[["13b230384ddde34d"]]},{"id":"f96044e72790dcd1","type":"status","z":"5caaf3ef1750712d","name":"","scope":["fd6b6e8e73d17fd7"],"x":180,"y":380,"wires":[["7c6caecf95ba2993"]]},{"id":"13b230384ddde34d","type":"function","z":"5caaf3ef1750712d","name":"","func":"\nmsg.id = 1;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":320,"wires":[["07bf8a66b718d8e8"]]},{"id":"7c6caecf95ba2993","type":"function","z":"5caaf3ef1750712d","name":"","func":"\nmsg.id = 2\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":380,"wires":[["07bf8a66b718d8e8"]]},{"id":"2441d7b0c195b6b2","type":"change","z":"5caaf3ef1750712d","name":"","rules":[{"t":"set","p":"priorityOne","pt":"msg","to":"priorityOneIdentifier","tot":"env"},{"t":"set","p":"priorityTwo","pt":"msg","to":"priorityTwoIdentifier","tot":"env"},{"t":"set","p":"priorityThree","pt":"msg","to":"priorityThreeIdentifier","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":200,"wires":[["e2b1931fa7499729"]]},{"id":"87d7b270c3b03f6b","type":"status","z":"5caaf3ef1750712d","name":"","scope":["4bb7268a5a5095b9"],"x":180,"y":460,"wires":[["78f4f46ba89d4efa"]]},{"id":"78f4f46ba89d4efa","type":"function","z":"5caaf3ef1750712d","name":"","func":"\nmsg.id = 3;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":440,"wires":[["07bf8a66b718d8e8"]]}]

Flow Info

Created 2 years, 6 months ago
Updated 2 years, 5 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • function (x5)
  • status (x3)
Other

Tags

  • Priority-Queue
  • Cloud
  • Backend
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option