aws-sqs-connector
v0.0.9
Published
Amazon WebService SQS Connector
Downloads
6
Readme
AWS SQS Connector
Tired of all the hassles connecting and polling a Amazon WebService SQS? The solution is here!
Install
npm install --save aws-sqs-connector
Initialize Queue
With CoffeeScript
SQSConnector = require 'aws-sqs-connector'
Queue = new SQSConnector
credentials: './credentials/aws.json'
queueUrl: 'http://sqs.<REGION>.amazonaws.com/<NUMBER>/queue-name'
With JavaScript
var SQSConnector = require('aws-sqs-connector');
var Queue = new SQSConnector({
credentials: './credentials/aws.json',
queueUrl: 'http://sqs.<REGION>.amazonaws.com/<NUMBER>/queue-name'
});
Poll Queue
With CoffeeScript
# Everytime there is a new message, this callback gets executed
Queue.receive (message, fetchNext) ->
# log message
console.log message
# log attributes
console.log message.attributes
# do some processing with the message and then fetch the next message
fetchNext()
With JavaScript
Queue.receive(function(message, fetchNext) {
console.log(message);
console.log(messages.attributes);
fetchNext();
});
Send Message
send MessageBody, MessageAttributes, Callback
With CoffeeScript
Queue.send 'message body', { responseRequired: true, randomNumber: 1 }, (err, response) ->
console.error(err) if err
console.log response
With JavaScript
Queue.send('message body', { responseRequired: true, randomNumber: 1 }, function(err, response) {
if (err) { console.error(err); }
console.log(response);
});
Options
- Credentials: The credentials json should be of the following format:
{
"accessKeyId": "YOUR_ACCESS_KEY_ID",
"secretAccessKey": "YOUR_SECRET_ACCESS_KEY",
"region": "YOUR_REGION"
}