The following screenshots visually describe a retry solution for Talend component connections. You can update the code to use context variables or global variables for the values that are hard-coded - wait time (2 seconds), number of retries (5).
Starting job - create a boolean context variable and set to true
// resetting loop flag
context.continueLooping = true;
log.info("Starting job...");
Set Condition on tLoop to variable on While loop
Now, connect to the resource - here MDM (could be FTP, web service, database etc...)
Using onComponentOK (for successful connection), set the boolean variable to false (to exit loop).
// on success, exit loop
context.continueLooping = false;
log.info("Connection established on attempt # " + ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")).toString());
Using onComponentError (for failed connection), retry for 5 times then proceed (which will fail the job); else retry the job.
if (((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")) > 5)
{
log.error("Connection failed. Exiting retry loop.");
// exit loop
context.continueLooping = false;
}
else
{
log.info("Connection failed. Retrying...");
}