sqs-consumer
Advanced tools
Comparing version 1.1.0 to 1.1.1
22
index.js
var EventEmitter = require('events').EventEmitter; | ||
var util = require('util'); | ||
var _ = require('lodash'); | ||
var AWS = require('aws-sdk'); | ||
@@ -11,6 +12,6 @@ var debug = require('debug')('sqs-consumer'); | ||
function validateOptions(options) { | ||
function validate(options) { | ||
requiredOptions.forEach(function (option) { | ||
if (!options[option]) { | ||
throw new Error('Missing SQS consumer option [' + option + '].'); | ||
throw new Error('Missing SQS consumer option [' + option + '].'); | ||
} | ||
@@ -30,10 +31,11 @@ }); | ||
function Consumer(options) { | ||
validateOptions(options); | ||
AWS.config.update({region: options.region}); | ||
validate(options); | ||
this.queueUrl = options.queueUrl; | ||
this.handleMessage = options.handleMessage; | ||
this.waitTime = options.waitTime || 100; | ||
this.stopped = true; | ||
this.sqs = options.sqs || new AWS.SQS(); | ||
this.sqs = options.sqs || new AWS.SQS({ | ||
region: options.region | ||
}); | ||
this.poll = _.throttle(this._poll.bind(this), options.waitTime || 100); | ||
} | ||
@@ -50,3 +52,3 @@ | ||
this.stopped = false; | ||
this._poll(); | ||
this.poll(); | ||
} | ||
@@ -76,3 +78,3 @@ }; | ||
Consumer.prototype._handleSqsResponse = function(err, response) { | ||
Consumer.prototype._handleSqsResponse = function (err, response) { | ||
if (err) this.emit('error', err); | ||
@@ -89,4 +91,4 @@ | ||
// Start polling for a new message after the wait time. | ||
setTimeout(this._poll.bind(this), this.waitTime); | ||
// Poll for another message | ||
this.poll(); | ||
}; | ||
@@ -93,0 +95,0 @@ |
{ | ||
"name": "sqs-consumer", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Build SQS-based Node applications without the boilerplate", | ||
@@ -30,4 +30,5 @@ "main": "index.js", | ||
"aws-sdk": "^2.0.23", | ||
"debug": "^2.1.0" | ||
"debug": "^2.1.0", | ||
"lodash": "^2.4.1" | ||
} | ||
} | ||
} |
11849
8
238
3
+ Addedlodash@^2.4.1
+ Addedlodash@2.4.2(transitive)