An AWS SQS wrapper providing high level helper methods.
Install the module using NPM:
npm install @waldo/sqs --save
The sqs library requires node 6+.
The library you require is a function that accepts the following options when invoked:
const sqsLib = require('@waldo/sqs');
const sqs = sqsLib({
sqsUrl: '...',
concurrentOpsLimit: 10,
logger: logger,
});
// Required
sqs.init()
.then(function() {
console.log('SQS Ready.');
})
.catch(function(err) {
console.error('SQS Failed to connect:', err);
})
sqsUrl
String Required The SQS url.concurrentOpsLimit
Number Required Number of concurrent processing of incoming jobs, Read notes bellow.logger
Object Required An object containing the methods: info, warn, error.
The AWS SQS library will only return up to 10 concurrent jobs per long-poll request as per their API. Special provisions had to be made in order to support more than 10 concurrent jobs consumptions so as to launch and monitor multiple long-poll requests. For this reason it is required that:
Beyond 10 concurrent jobs you need to define in increments of 10. E.g. 20, 30, 40...
const sqsLib = require('@waldo/sqs');
const sqs = sqsLib({
sqsUrl: '...',
concurrentOpsLimit: 10,
logger: logger,
});
sqs.createJob({
a: 1,
})
.then(function() {
console.log('job created!');
})
.catch(function(err) {
console.error('Error creating job');
});
Job consumption expects a handler that returns a Promise. You return a Promise, the library awaits until you are finished. Once you are done, resolve or reject the promise.
If the job resolves (or returns any other value than a promise) then AWS SQS is notified that the job has been complete.
If the job rejects (or throws) then AWS SQS will not be notified and the job will come back for processing as per the queue rules.
const sqsLib = require('@waldo/sqs');
const sqs = sqsLib({
sqsUrl: '...',
concurrentOpsLimit: 10,
logger: logger,
});
sqs.startFetch(function(jobItem) {
return new Promise(function(resolve, reject) {
my_async_job()
.then(resolve)
.catch(reject);
});
});
For testing purposes you are allowed to perform the purge operation. To be able to perform the purge it is required to include test
within the SQS's url.
const sqsLib = require('@waldo/sqs');
const sqs = sqsLib({
sqsUrl: '...',
logger: logger,
});
sqs.purge()
.then(function() {
console.log('Queue Purged');
});
- Update the changelog bellow.
- Ensure you are on master.
- Type:
grunt release
grunt release:minor
for minor number jump.grunt release:major
for major number jump.
- v0.2.2, 04 Mar 2017
- Reduced logging verbosity.
- v0.2.1, 03 Mar 2017
- Tweaked core loop.
- v0.2.0, 02 Mar 2017
- Now supports consuming more than 10 concurrent jobs.
- v0.1.1, 17 Jan 2017
- More robust disposing and check if instance is disposed.
- v0.1.0, 17 Jan 2017
- Added
.dispose()
method no instance for testing.
- Added
- v0.0.2, 10 Jan 2017
- Exposed
purge()
method and added protection to only purge test queues.
- Exposed
- v0.0.1, 05 Jan 2017
- Big Bang
Copyright Waldo, Inc. All rights reserved.