Skip to content

Instantly share code, notes, and snippets.

@riston
Created March 5, 2015 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save riston/087124c2323b00167576 to your computer and use it in GitHub Desktop.
Save riston/087124c2323b00167576 to your computer and use it in GitHub Desktop.
SQS recursive polling
var aws = require('aws-sdk');
var util = require('util');
var SQS = new aws.SQS({
accessKeyId: 'xxxx',
secretAccessKey: 'xxx',
region: 'xxx',
sslEnabled: false,
paramValidation: true,
convertResponseTypes: true,
apiVersion: "2012-11-05"
});
var queueUrl = 'xxxxx';
var formatMsg = function (mem) {
console.log([mem.rss, mem.heapTotal, mem.heapUsed].join(','));
};
var getMessage = function () {
formatMsg(process.memoryUsage());
SQS.receiveMessage({
QueueUrl: queueUrl,
MaxNumberOfMessages: 1,
VisibilityTimeout: 30,
WaitTimeSeconds: 20
}, function (err) {
if (err) {
return err;
}
// No need for result
// console.log(res);
// Recursive call
getMessage();
});
};
getMessage();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment