OFF-SQS: Manage SQS on node.js
This easy manager provides the basic functionality to use Amazon SQS. To start using it just clone it or install it via npm npm install off-sqs
and edit the aws-config.json
:
{
"accessKeyId": "STRING",
"secretAccessKey": "STRING",
"region": "STRING"
}
###NOTE that every operation checks first if the Queue exists, if not it'll create it.
Methods
Sender
Params: the name of the SQS queue and the data you want to send.
Returns: nothing.
Usage: sqs.sender('myQueue', ["foo": "bar"]);
##Receiver
Params: the name of the SQS queue.
Return: a promise which it became a tuple of receiver
a function and queueUrl
a string.
Usage:
sqs.receiver('myQueue').then(function(Receiver){
Receiver.receiver(yourDataManager, Receiver.url);
}
Note: Where yourDataManager
is a function that receives every message on the queue, so you can easy custom your data miner. Something like: `myMiner(messageOfTheQueue);``
##getQueueUrl
Params: The name of the SQS Queue.
Returns: A promise which became the url of the Queue.
Usage:
sqs.getQueueUrl('myQueue').then(function('myQueueURL'){
return myQueueURL;
});
##parseMessage
Params: Data received by SQS Queues.
Returns: The cleaned data of the body
as array.
Usage: sqs.parseMessage(data);
#Examples
##Sender example
sqs_off.sender("queue_name", data_to_send);
##Receiver example
In the receiver method, we need to the functionality of process data as a function.
sqs_off.receiver("queue_name").then(function(data){
data.receiver(save_data, data.url);
});
var save_data = function(data){
//save your data
}