Hi,
I’m excited to announce the release of my new node, designed to simplify the implementation of retries within Node-RED flows.
Motivation
I use Node-RED to manage my smart home, which involves interacting with various devices, bus systems, internet services, and more. Unfortunately, some of these devices or services occasionally fail to respond, return errors, or become unreachable.
Since many of these systems are essentially "black boxes" for me, I can’t always address the root causes. Instead, I want to build a system that is as robust as possible against these sporadic issues.
In many cases, simply retrying the request or query to the device or service solves the problem.
However, I couldn’t find an existing Node-RED node that simplifies implementing the necessary retry loops. The only resource I came across was the cookbook article, 'Automatically retry an action after an error', which provides some guidance on implementing a retry mechanism.
A key limitation of the pattern described in the article is that it can lead to an infinite loop if the error can’t be resolved through retries. Additionally, the pattern only works if the caught msg
contents are not altered by the flow.
Solution
After experimenting with a subflow template, I decided to develop a new node that simplifies creating retry flows and loops. This node essentially stores the last valid message and resends it if an error is reported. The retries are capped at a configurable maximum and can be optionally delayed (similar to the Delay node).
This is the new born node:
Future
There are several ideas for future improvements:
- Independent retry state per
msg.topic
- More advanced retry strategies (e.g.,
N
fast retries followed byM
slower retries) - Dynamic control through
msg
properties.- Set the retry strategy using
msg.strategy
- Set delay time using
msg.delay
- Set the retry strategy using
I hope this node will be useful to many other Node-RED enthusiasts.
I'm eager to receive constructive feedback!