2.0.0 • Published 11 years ago
sqs-processor v2.0.0
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_callbackis passed two arguments (message,callback) wheremessageis an Object containing data andcallbackis a function that must be called when you are finished processing the message. If you pass anErrorinto thecallbackthenerror_callbackwill be called with your error. If you do not pass anErrorinto thecallbackthen the message will be removed from the queue.error_callbackis passed one argument (error) whereerroris anError.
stopPolling(stop_callback)stop_callbackis 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.