sqs-aws-sdk
v1.0.0
Published
Push and pull from SQS using the AWS SDK
Downloads
10
Readme
sqs-aws-sdk
A message queue using Amazon Simple Queue Service using the AWS SDK. This module has the same interface of sqs, but uses the AWS SDK instead of a custom API wrapper.
Install
npm install sqs-aws-sdk
Usage
var AWS = require('aws-sdk')
// see the AWS SQS in how to configure it
var sdk = new AWS.SQS()
var sqs = require('sqs-aws-sdk')
var queue = sqs(sdk)
// push some data to the test queue
queue.push('test', {
some:'somedata'
})
// pull messages from the test queue
queue.pull('test', function(message, callback) {
console.log('someone pushed', message)
callback() // we are done with this message - pull a new one
// callbackling the callback will also delete the message
// from the queue
queue.stop() // stops the queue for receiving any other messages
})
API
sqs(sdk)
Create a queue instance
var queue = sqs(sdk)
queue.push(name, message, callback)
queue.push(name, message)
Push a new message to the queue defined by name.
The queue needs to exits.
queue.pull(name, [opts], onMessage)
Pull messages from the queue defined by name.
The pull flow is as follows:
- A message is pulled and is passed to
onMessage(message, callback)
- You process the message
- Call
callback
when you are done and the message will be deleted from the queue. - Goto 1
If for some reason the callback is not called amazon sqs will re-add the message to the queue after 5 minutes.
The options include all the options accepted by the aws-sdk receiveMessage, plus:
wait
: the number of seconds to wait between every loop roundworkers
: the number of calls to be done to SQS in parallelraw
: if you do not want the message to be parsed as JSON
Fault tolerance
Both pull
and push
will retry multiple times if a network error
occurs or if amazon sqs is temporary unavailable.
Acknowledgements
This project was kindly sponsored by nearForm. It was extracted from aws-autoscaling-container.
@mafintosh for its awesome sqs module. Part of the doc was borrowed from that module, and also for the API contract.
@Nss for its work on the nScale aws-autoscaling-container.
License
MIT