How to retry a single message for x times should it encounter an error?

Hi Forum,
I am working on a small project where I have to retry each message coming from an mqtt-in node for three times should the message encounter an error. I tried using catch node to catch the error but couldn't retry the error message for 3 times. Any help is appreciated !!!

What sort of error do you mean?

if you can catch the error with a catch node then you can use msg.error.source.count and a switch node to allow three retries

e.g.

[{"id":"74013b85c3dbbf1f","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":3680,"wires":[["aa31269ca6e7b385"]]},{"id":"aa31269ca6e7b385","type":"function","z":"452103ea51141731","name":"function 17","func":"node.error(\"testerror\",msg)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":3680,"wires":[["3100195536aa61cc"]]},{"id":"a74c2f591f18c947","type":"delay","z":"452103ea51141731","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":520,"y":3760,"wires":[["aa31269ca6e7b385"]]},{"id":"3100195536aa61cc","type":"debug","z":"452103ea51141731","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":3680,"wires":[]},{"id":"f8f03081edea7cf5","type":"switch","z":"452103ea51141731","name":"","property":"error.source.count","propertyType":"msg","rules":[{"t":"lt","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":3800,"wires":[["0a4f503a989355f6","a74c2f591f18c947"]]},{"id":"544ad9ac0419193d","type":"catch","z":"452103ea51141731","name":"","scope":["aa31269ca6e7b385"],"uncaught":false,"x":270,"y":3800,"wires":[["f8f03081edea7cf5"]]},{"id":"0a4f503a989355f6","type":"debug","z":"452103ea51141731","name":"debug 108","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":3800,"wires":[]}]

I don't see how what you describe makes sense with an MQTT In node, which is why I ask what sort of error the MQTT node is generating.

Hi @E1cid Thanks for the solution.
Now your retry mechanism seems to work as expected.

I have a postgres node which throws an error message but in the catch node the payload attribute has both error and payload data merged. Trying to seperate the payload with the help of flow context.

Oh, I thought you said it was MQTT that was causing the problem. So the fact that the messages come from MQTT is completely irrelevant.

Yes it is. I was using the mqtt-in node to get trigger.

Whether the message came from mqtt or somewhere else is irrelevant.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.