3

我需要像这样处理吗:

ses.sendEmail( //body and other options
}, function (err, data) {
   if (err)
    //parse error and attmept to retry
});

还是仅通过以下方式处理它来完成:

var ses = new aws.SES({apiVersion: apiVersion,maxRetries: 10});
4

1 回答 1

3

AFAIK aws sdk 不处理速率限制。使用这个 速率限制 模块来包装你的 ses.send 像这样,

var RateLimiter = require('limiter').RateLimiter;
// Allow 50 requests per second. Also understands
// 'second', 'minute', 'day', or a number of milliseconds
var limiter = new RateLimiter(50, 'second');

//huge number of requests
for (var i = 0; i < 10000; i++) {
//Throttle requests
  limiter.removeTokens(1, function (err) {
    if (err) throw err
    // err will only be set if we request more than the maximum number of
    // requests we set in the constructor
    // remainingRequests tells us how many additional requests could be sent
    // right this moment
    ses.sendEmail({
      //body and other options
    }, function (err, data) {
      if (err) throw err
      //parse error and attempt to retry

    })

  });
}
于 2017-04-25T13:07:52.420 回答