A tiny abstraction for working with SQS.
The name qDog may be a bit dog biased but lets be honest, qCat.fetch() just seems doomed to failure, and "CueCat" ended pretty badly for RadioShack already.
npm install qdog
const QDog = require('qdog');
const qDog = new QDog({
accessKeyId: process.env.ACCESS_KEY_ID,
secretAccessKey: process.env.SECRET_ACCESS_KEY,
queueUrl: process.env.SQS_QUEUE_URL,
maxMessages: 10 // number of messages to read from SQS, default is 1
});
qDog.toss({'some':'data'});
qDog.toss({'some':'data'}, {delaySeconds: 120});
qDog.fetch().then(function(messages) {
assert(Array.isArray(messages)); // true
console.log('Got:', messages[0].body);
qDog.drop(message[0].id);
},function(err) {
if (err) throw err;
});
qDog.drop(message.id);
SQS is a pull based queue. A common usage pattern to process new incoming messages is to use a retry loop. For example:
var processError = function(err) {
if (err) throw err;
}
var processMessages = function(messages) {
console.log('Got:',messages);
qDog.drop(messages[0].id);
qDog.fetch().then(processMessage, processError);
}
qDog.fetch().then(processMessages, processError);
Unit:
npm test
End-To-End:
cp .env.sample .env
vim .env
mocha tests/e2e/*