-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a 2 minute session expiry on the mqtt connection #69
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pulling and testing with e2e flows that operate across the broker. |
Steve-Mcl
approved these changes
May 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally with an e2e flow that runs device -> instance & instance -> device
messages now catch up once connection is re-established
Demo flow for future readers:
[{"id":"fd79fa93b6853c80","type":"comment","z":"06a2836c9f2ae124","name":"Instance → Device","info":"","x":130,"y":520,"wires":[]},{"id":"e355245f7c6092bb","type":"comment","z":"06a2836c9f2ae124","name":"Device → Instance ","info":"","x":130,"y":40,"wires":[]},{"id":"4b6d2c3c162d84d7","type":"inject","z":"06a2836c9f2ae124","name":"reset counters","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":360,"y":40,"wires":[["c0b579731ce0a835"]]},{"id":"c0b579731ce0a835","type":"link out","z":"06a2836c9f2ae124","name":"link out 1","mode":"link","links":["30dceea6235f39dc","2cb326268111a5d4"],"x":465,"y":40,"wires":[]},{"id":"e49daf0d15718faf","type":"group","z":"06a2836c9f2ae124","name":"Device Part","style":{"label":true},"nodes":["d71d6c56ca8e66a6","46089c2249a3afb2","e8266c879eda8382","55362646ce57faa3","1717cc7325fa5d7f","d2ec13e800b9f726","84b4e3ccf6bd4522","8cf2c0091a53b5a8","30dceea6235f39dc"],"x":34,"y":79,"w":852,"h":162},{"id":"d71d6c56ca8e66a6","type":"inject","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":156,"y":120,"wires":[["84b4e3ccf6bd4522"]]},{"id":"46089c2249a3afb2","type":"function","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"counter","func":"if (msg.topic === \"reset\" || msg.reset) {\n context.set('counter', undefined)\n return\n}\n\nconst counter = context.get('counter') || 0\n\nmsg.payload = counter + 1\n\nif (msg.payload > 1000) {\n msg.payload = 1\n}\n\ncontext.set('counter', msg.payload)\nnode.status({ fill: \"grey\", shape: \"ring\", text: \"sending:\" + counter });\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":506,"y":120,"wires":[["e8266c879eda8382"]]},{"id":"e8266c879eda8382","type":"project link out","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"broadcast counter →","mode":"link","broadcast":true,"project":"3b39f2c4-eb4d-43dd-99b0-a47ca106cd40","topic":"counter","x":760,"y":120,"wires":[]},{"id":"55362646ce57faa3","type":"project link in","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"→ counter-resp broadcast","project":"3b39f2c4-eb4d-43dd-99b0-a47ca106cd40","broadcast":true,"topic":"counter-resp","x":170,"y":200,"wires":[["8cf2c0091a53b5a8"]]},{"id":"1717cc7325fa5d7f","type":"debug","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"send to instance","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":740,"y":200,"wires":[]},{"id":"d2ec13e800b9f726","type":"function","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"check counter","func":"if (msg.topic === \"reset\" || msg.reset) {\n context.set('counter_next', undefined)\n return\n}\n\nlet counter_next = flow.get('counter_next') || (msg.payload + 1)\n\nif (msg.payload !== counter_next) {\n const errMsg = `Got counter ${msg.payload} expected ${counter_next}`\n counter_next = msg.payload\n node.error(errMsg, msg);\n}\n\ncounter_next += 1\nif (counter_next > 1000) {\n counter_next = 1\n}\nflow.set('counter_next', counter_next)\nnode.status({ fill: \"grey\", shape: \"ring\", text: `waiting for: ${counter_next}` });\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":200,"wires":[["1717cc7325fa5d7f"]]},{"id":"84b4e3ccf6bd4522","type":"switch","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"Is Device?","property":"FF_DEVICE_ID","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":336,"y":120,"wires":[["46089c2249a3afb2"]]},{"id":"8cf2c0091a53b5a8","type":"switch","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"Is Device?","property":"FF_DEVICE_ID","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":200,"wires":[["d2ec13e800b9f726"]]},{"id":"30dceea6235f39dc","type":"link in","z":"06a2836c9f2ae124","g":"e49daf0d15718faf","name":"link in 1","links":["c0b579731ce0a835"],"x":415,"y":160,"wires":[["46089c2249a3afb2","d2ec13e800b9f726"]]},{"id":"8ffe5c4bdc1fd7ad","type":"group","z":"06a2836c9f2ae124","name":"Instance Part","style":{"label":true},"nodes":["851c2534e8769c51","9f88f68f21c1f546","cedc767d2b9ac3e3","c5b3680e86e958d7","4a35a3fdc9ce8d88","304e7d3bdcf20f24","f36969b3f702a5fd","dea66722de4ab7be","2cb326268111a5d4"],"x":34,"y":559,"w":792,"h":162},{"id":"851c2534e8769c51","type":"inject","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":156,"y":600,"wires":[["f36969b3f702a5fd"]]},{"id":"9f88f68f21c1f546","type":"function","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"counter","func":"if (msg.topic === \"reset\" || msg.reset) {\n context.set('counter', undefined)\n return\n}\n\nconst counter = context.get('counter') || 0\n\nmsg.payload = counter + 1\n\nif (msg.payload > 1000) {\n msg.payload = 1\n}\n\ncontext.set('counter', msg.payload)\nnode.status({ fill: \"grey\", shape: \"ring\", text: \"sending:\" + counter });\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":506,"y":600,"wires":[["cedc767d2b9ac3e3"]]},{"id":"cedc767d2b9ac3e3","type":"project link out","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"broadcast counter2 →","mode":"link","broadcast":true,"project":"3b39f2c4-eb4d-43dd-99b0-a47ca106cd40","topic":"counter2","x":700,"y":600,"wires":[]},{"id":"c5b3680e86e958d7","type":"project link in","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"→ counter2-resp broadcast","project":"all","broadcast":true,"topic":"counter2-resp","x":170,"y":680,"wires":[["dea66722de4ab7be"]]},{"id":"4a35a3fdc9ce8d88","type":"debug","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"debug 11","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":720,"y":680,"wires":[]},{"id":"304e7d3bdcf20f24","type":"function","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"check counter","func":"if (msg.topic === \"reset\" || msg.reset) {\n context.set('counter_next', undefined)\n return\n}\n\nlet counter_next = flow.get('counter_next') || (msg.payload + 1)\n\nif (msg.payload !== counter_next) {\n const errMsg = `Got counter ${msg.payload} expected ${counter_next}`\n counter_next = msg.payload\n node.error(errMsg, msg);\n}\n\ncounter_next += 1\nif (counter_next > 1000) {\n counter_next = 1\n}\nflow.set('counter_next', counter_next)\nnode.status({ fill: \"grey\", shape: \"ring\", text: `waiting for: ${counter_next}` });\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":680,"wires":[["4a35a3fdc9ce8d88"]]},{"id":"f36969b3f702a5fd","type":"switch","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"Is Instance?","property":"FF_INSTANCE_ID","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":336,"y":600,"wires":[["9f88f68f21c1f546"]]},{"id":"dea66722de4ab7be","type":"switch","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"Is Instance?","property":"FF_INSTANCE_ID","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":680,"wires":[["304e7d3bdcf20f24"]]},{"id":"2cb326268111a5d4","type":"link in","z":"06a2836c9f2ae124","g":"8ffe5c4bdc1fd7ad","name":"link in 2","links":["c0b579731ce0a835"],"x":405,"y":640,"wires":[["9f88f68f21c1f546","304e7d3bdcf20f24"]]},{"id":"a52fa0288cbeca42","type":"group","z":"06a2836c9f2ae124","name":"Device part","style":{"label":true},"nodes":["58b52c1135eca942","beb558b722ac4089","d12dc1edee4fd8b4","5108b42cc9e6c0e5"],"x":40,"y":739,"w":826,"h":142},{"id":"58b52c1135eca942","type":"project link in","z":"06a2836c9f2ae124","g":"a52fa0288cbeca42","name":"→ broadcast counter2","project":"all","broadcast":true,"topic":"counter2","x":166,"y":780,"wires":[["5108b42cc9e6c0e5"]]},{"id":"beb558b722ac4089","type":"project link out","z":"06a2836c9f2ae124","g":"a52fa0288cbeca42","name":"broadcast counter2-resp →","mode":"link","broadcast":true,"project":"7db963e4-6794-40f1-831f-b0920b2eba45","topic":"counter2-resp","x":720,"y":780,"wires":[]},{"id":"d12dc1edee4fd8b4","type":"debug","z":"06a2836c9f2ae124","g":"a52fa0288cbeca42","name":"reply to instance","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":840,"wires":[]},{"id":"5108b42cc9e6c0e5","type":"switch","z":"06a2836c9f2ae124","g":"a52fa0288cbeca42","name":"Is Device?","property":"FF_DEVICE_ID","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":780,"wires":[["beb558b722ac4089","d12dc1edee4fd8b4"]]},{"id":"77682232d6025f79","type":"group","z":"06a2836c9f2ae124","name":"Instance part","style":{"label":true},"nodes":["a8ab659e63645d40","857f271e63e63b07","5fc111ed246d1ae0","1e0a7c1730b5250d"],"x":40,"y":259,"w":806,"h":142},{"id":"a8ab659e63645d40","type":"project link in","z":"06a2836c9f2ae124","g":"77682232d6025f79","name":"→ broadcast counter","project":"all","broadcast":true,"topic":"counter","x":156,"y":300,"wires":[["1e0a7c1730b5250d"]]},{"id":"857f271e63e63b07","type":"project link out","z":"06a2836c9f2ae124","g":"77682232d6025f79","name":"broadcast counter-resp → ","mode":"link","broadcast":true,"project":"7db963e4-6794-40f1-831f-b0920b2eba45","topic":"counter-resp","x":710,"y":300,"wires":[]},{"id":"5fc111ed246d1ae0","type":"debug","z":"06a2836c9f2ae124","g":"77682232d6025f79","name":"reply to device","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":680,"y":360,"wires":[]},{"id":"1e0a7c1730b5250d","type":"switch","z":"06a2836c9f2ae124","g":"77682232d6025f79","name":"Is Instance?","property":"FF_INSTANCE_ID","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":300,"wires":[["857f271e63e63b07","5fc111ed246d1ae0"]]}]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #68
This updates the project nodes to connect with a non-clean session, meaning session state is not immediately expired when the node disconnects. Alongside this, setting the session expiry to 2 minutes so we don't queue up messages indefinitely.
The choice of a 2 minute session expiry means we'll handle brief connectivity blips without discarding messages.
If the project nodes are disconnected for more than 2 minutes, we'll stop queuing up messages for it (something we didn't do at all previously).