Sidebar

How to automate resolving errors?

+1 vote
517 views
asked Jun 9, 2016 by rich-c-2789 (16,180 points)
I have several message that error trying to send to a destination.  It seems the destination is down or overwhelmed.  If I wait a few minutes and try these messages again by resolving them in the error queue, they go through fine.  Since there is nothing I can do to about the errors returned by the destination, is there a way that I can automatically retry these errored messages later?

1 Answer

+1 vote

As of version 44 see the new "Error Management" menu in the "Code Wizard".  

NOTE: "Error Management" is only available from schedule scripts.

NOTE: Before using these new function see the "Error Management" tab in the "Channel Properties".  This should be the first line of defense against errors caused by the destination system. 

 

Here is and example to automate "disgracefulWebServiceFailure" errors.  This error is fabricated.  Replace "disgracefulWebServiceFailure" with the error to automate.

First, from the "Schedule Scripts" tab insert a new schedule script.  In the example below I selected "Run script when channel starts" but it might make sense to choose a CRON string to run more frequently on a schedule that best suits the need.

NOTE: To disable a script from running delete the CRON string and uncheck the "Run..." chechboxes.  In this way the scheduled script will not run.

Here is the code used in the above screen shot:

//See if there are any errors using the existing code wizard function before we do anything.
//This is a quick test that avoids the searchErrors call if it is not needed.
if (qie.getErrorCount() > 0) {
   var searchText = 'error=disgracefulWebServiceFailure';
   
   //NEW: Search for errors that match the searchText
   var results = errorManager.searchErrors(searchText);
   qie.debug('searchErrors returned ' + results.size() + ' messageQueueIds.');
   qie.debug('The messageQueueIds returned: ' + results);
   
   var messagesResolved = 0;
   for (var i=0 ; i < results.size() ; i++) {
      var messageQueueId = results.get(i);
      //NEW: Use oo get the error details.  Ignored for now.
      var error = errorManager.getErrorDetail(messageQueueId);
      qie.debug('error: ' + error);
      //NEW: Use to get the messages source model.  Used to check the source for "Bad Value"s and update with "Good Value"
      var errorSource = errorManager.getSource(messageQueueId);
      qie.debug('errorSource: ' + errorSource);
      //NEW: Use to get the messages message model.  Ignored for now.
      var errorMessage = errorManager.getMessage(messageQueueId);
      qie.debug('errorMessage: ' + errorMessage);
 
      //if there is no parent then this message has not been previously resubmitted or resolved
      if (!errorManager.hasParent(messageQueueId)) {
         if (errorSource !== null) {
            if (StringUtils.equals(errorSource.getNode('PID-33.1'), 'Bad Value')) {
               //modify the source
               errorSource.setNode('PID-33.1', 'Good Value');
               errorManager.resolveError(messageQueueId, errorSource);
               messagesResolved++;
            } else {
               qie.debug("This message does not contain 'Bad Value'.  Skipping");
            }
         } else {
            qie.debug('This message does not contain a valid source.  Skipping');
         }
      } else {
         qie.debug('This message queue was previously resolved.  Skipping');
      }
   }
   qie.debug('Finished resolving errors');
   qie.queueEmail('rabbit@acme.ltunes.com', 'Auto error resolution summary', 'Resolved ' + messagesResolved + ' errors.');
} else {
   qie.debug('No errors found.  Nothing to resolve.');
}
 
 
Also see these questions:
 
 
 
 
 
 
answered Jun 9, 2016 by rich-c-2789 (16,180 points)
...