qdog
v2.0.0
Published
SQS with an attitude
Downloads
7
Readme
qdog
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.
Examples
Include / Configure
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
});
Toss a message into the Queue
qDog.toss({'some':'data'});
With a delay
qDog.toss({'some':'data'}, {delaySeconds: 120});
Fetch messages from the queue
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;
});
Drop a message no one cares about anymore.
qDog.drop(message.id);
Continually poll for new messages
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);
Run Tests
Unit:
npm test
End-To-End:
cp .env.sample .env
vim .env
mocha tests/e2e/*