Parametered Retry
The developed Node-RED flow exemplifies the successful integration of two distinct retry methods, namely fixed-interval retries and retries with varying intervals, thereby enhancing the resilience and fault tolerance of cloud-based applications. By incorporating a parameter-driven approach, where the choice of retry method is determined by the message parameter, the flow demonstrates adaptability and flexibility in handling transient failures in a dynamic manner.
The integration of both fixed-interval retries and retries with varying intervals within the Node-RED flow provides developers with a comprehensive toolbox for addressing transient failures effectively. The fixed-interval retry strategy ensures a consistent and predictable retry pattern, suitable for scenarios where a stable retry interval is preferred. On the other hand, the retries with varying intervals allow the flow to dynamically adjust the retry attempts based on the current conditions of the cloud environment, optimizing the chances of successful recovery in complex and dynamic scenarios.
The parameter-driven approach implemented in the flow empowers users to select the appropriate retry method based on the specific requirements of the cloud-based application. This flexibility allows for fine-grained control over the retry behavior, enabling developers to optimize the trade-off between reliability, resource utilization, and responsiveness. By following this exemplary implementation, developers can effectively leverage Node-RED's capabilities to design resilient cloud architectures that can seamlessly adapt to varying failure conditions, resulting in improved system reliability and user experience.
[{"id":"82686e4920016746","type":"subflow","name":"Varying Interval Retry","info":"","category":"","in":[{"x":120,"y":160,"wires":[{"id":"6ec4235854dd0c41"}]}],"out":[{"x":1380,"y":140,"wires":[{"id":"d8c2072b43f75c90","port":0},{"id":"bc4468a2764edbe2","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"6ec4235854dd0c41","type":"function","z":"82686e4920016746","name":"","func":"msg.delay = msg.retry_interval;\nmsg.retry_counter = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":160,"wires":[["653de01a06106298"]]},{"id":"653de01a06106298","type":"delay","z":"82686e4920016746","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":420,"y":160,"wires":[["18096c13cd933552"]]},{"id":"18096c13cd933552","type":"http request","z":"82686e4920016746","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":570,"y":160,"wires":[["4af1fb2b6c4115da"]]},{"id":"d8c2072b43f75c90","type":"switch","z":"82686e4920016746","name":"if success","property":"statusCode","propertyType":"msg","rules":[{"t":"btwn","v":"200","vt":"num","v2":"299","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":920,"y":160,"wires":[[],["bc4468a2764edbe2"]]},{"id":"4af1fb2b6c4115da","type":"function","z":"82686e4920016746","name":"counter increment","func":"msg.retry_counter++;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":160,"wires":[["d8c2072b43f75c90"]]},{"id":"bc4468a2764edbe2","type":"switch","z":"82686e4920016746","name":"if max retries","property":"retry_counter","propertyType":"msg","rules":[{"t":"gte","v":"n_retries","vt":"msg"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1070,"y":220,"wires":[[],["8e49f5940f8d2a39"]]},{"id":"8e49f5940f8d2a39","type":"function","z":"82686e4920016746","name":"change interval","func":"msg.delay *= msg.retry_interval_multiplier;\nmsg.retry_interval = msg.delay;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1280,"y":220,"wires":[["653de01a06106298","c1eb97959e60060a"]]},{"id":"c1eb97959e60060a","type":"debug","z":"82686e4920016746","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1440,"y":300,"wires":[]},{"id":"e976c9069888c66c","type":"subflow","name":"Simple Retry","info":"","category":"","in":[{"x":140,"y":120,"wires":[{"id":"50b54310bc44b2ce"}]}],"out":[{"x":1320,"y":120,"wires":[{"id":"3eb4ec6b71fc383b","port":0},{"id":"bad4bdb7e00b7a80","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"50b54310bc44b2ce","type":"function","z":"e976c9069888c66c","name":"","func":"msg.delay = msg.retry_interval;\nmsg.retry_counter = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":120,"wires":[["b4eca1de14599dd1"]]},{"id":"b4eca1de14599dd1","type":"delay","z":"e976c9069888c66c","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":440,"y":120,"wires":[["96ca1ed69e7fa7ac"]]},{"id":"96ca1ed69e7fa7ac","type":"http request","z":"e976c9069888c66c","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":590,"y":120,"wires":[["4442b04b4a071572"]]},{"id":"3eb4ec6b71fc383b","type":"switch","z":"e976c9069888c66c","name":"if success","property":"statusCode","propertyType":"msg","rules":[{"t":"btwn","v":"200","vt":"num","v2":"299","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":940,"y":120,"wires":[[],["bad4bdb7e00b7a80"]]},{"id":"4442b04b4a071572","type":"function","z":"e976c9069888c66c","name":"counter increment","func":"msg.retry_counter++;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":120,"wires":[["3eb4ec6b71fc383b"]]},{"id":"bad4bdb7e00b7a80","type":"switch","z":"e976c9069888c66c","name":"if max retries","property":"retry_counter","propertyType":"msg","rules":[{"t":"gte","v":"n_retries","vt":"msg"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1110,"y":160,"wires":[[],["b4eca1de14599dd1","0fb09013857b9001"]]},{"id":"0fb09013857b9001","type":"debug","z":"e976c9069888c66c","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1320,"y":220,"wires":[]},{"id":"7cf2bbfb7f9722e1","type":"subflow","name":"Parametered Retry","info":"","category":"","in":[{"x":40,"y":240,"wires":[{"id":"57bdb2513d445a10"}]}],"out":[{"x":1200,"y":240,"wires":[{"id":"f2b2dc3858eeaec8","port":0},{"id":"1cc48c4373b76f9e","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"1010e1cf89fd49f6","type":"switch","z":"7cf2bbfb7f9722e1","name":"","property":"retry_type","propertyType":"msg","rules":[{"t":"eq","v":"simple","vt":"str"},{"t":"eq","v":"varying","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":550,"y":240,"wires":[["f2b2dc3858eeaec8"],["1cc48c4373b76f9e"],["6456d6c4f28e8a9b"]]},{"id":"57bdb2513d445a10","type":"http request","z":"7cf2bbfb7f9722e1","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":190,"y":240,"wires":[["7797781dece51a7a"]]},{"id":"7797781dece51a7a","type":"switch","z":"7cf2bbfb7f9722e1","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"btwn","v":"200","vt":"num","v2":"299","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":240,"wires":[[],["1010e1cf89fd49f6"]]},{"id":"f2b2dc3858eeaec8","type":"subflow:e976c9069888c66c","z":"7cf2bbfb7f9722e1","name":"Simple Retry","x":840,"y":140,"wires":[[]]},{"id":"1cc48c4373b76f9e","type":"subflow:82686e4920016746","z":"7cf2bbfb7f9722e1","name":"","x":860,"y":240,"wires":[[]]},{"id":"6456d6c4f28e8a9b","type":"function","z":"7cf2bbfb7f9722e1","name":"Throw unsupported operation error","func":"throw new Error(\"Unsupported operation.\");","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":910,"y":340,"wires":[[]]}]