sqs-processor
v2.0.0
Published
SQS Processor
Downloads
61
Readme
sqs-processor
SQS processor for nodejs
Example
var SQSProcessor = require('sqs-processor');
var queue = new SQSProcessor({
accessKeyId: 'aws id',
secretAccessKey: 'aws secret',
region: 'aws region',
queueUrl: 'queue url'
});
queue.startPolling(
function worker(message, callback) {
// Do something with the message
console.log(message)
// Then remove the message from the queue
callback();
},
function error(queueError) {
// Oh no, we received an error!
// No worries, we'll just log it and let ops worry about it
console.error(queueError);
}
);
setTimeout(function() {
queue.stopPolling(function stop() {
console.log('stopped polling');
});
}, 10000);
Constructor options
accessKeyId
- required String- Your AWS access key ID.
secretAccessKey
- required String- Your AWS secret access key.
region
- required String- The region to send service requests to.
queueUrl
- required String- The URL of the Amazon SQS queue to fetch messages from.
API
startPolling(worker_callback, error_callback)
worker_callback
is passed two arguments (message
,callback
) wheremessage
is an Object containing data andcallback
is a function that must be called when you are finished processing the message. If you pass anError
into thecallback
thenerror_callback
will be called with your error. If you do not pass anError
into thecallback
then the message will be removed from the queue.error_callback
is passed one argument (error
) whereerror
is anError
.
stopPolling(stop_callback)
stop_callback
is passed no arguments. It will be called once the queue has stopped polling. If you currently have a message in progress, it will wait until that message is processed before stopping.