Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Setting up delay for retrying backend

Not applicable
How to setup a delay for retrying backend service in APIGEE? I tried using setTimeout in javascript as below,
setTimeout(function() {
  context.setVariable("response.content",backend.getResponse().status);
}, 2000);
But its throwing setTimeout undefined error.
Solved Solved
1 7 1,729
2 ACCEPTED SOLUTIONS

The snippet you are showing would't help retrying the backend anyways. For such usecases, I would recommend using nodejs - it should be pretty straightforward to implement such orchestration in node Thanks, PS: 'setTimeout' isn't available for the JS policy,

View solution in original post

Not applicable
Yes. As suggested by @Mukundha Madhavan, it is recommended to leverage Node.js to handle replays. I've tried in the past on a local Node.js app request-replay Node.js package https://www.npmjs.com/package/request-replay. As per the package example, the benefit is that you continue to leverage request module wrapped by the replay module.
var fs = require('fs');
var request = require('request');
var replay = require('request-replay');
 
// Note that the options argument is optional 
// Accepts the same options the retry module does and an additional 
// errorCodes array that default to ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT'] 
replay(request('http://google.com/doodle.png', function (err, response, body) {
    // Do things 
}), {
    retries: 10,
    factor: 3
})
.on('replay', function (replay) {
    // "replay" is an object that contains some useful information 
    console.log('request failed: ' + replay.error.code + ' ' + replay.error.message);
    console.log('replay nr: #' + replay.number);
    console.log('will retry in: ' + replay.delay + 'ms')
})
 

View solution in original post

7 REPLIES 7