Skip to content

jmac105/easy-sqs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easy-sqs

easy-sqs is a simpler wrapper for the AWS SQS service.

How to install

npm install easy-sqs

How to use

var easy = require("easy-sqs");


var awsConfig = {
	"accessKeyId": "[YourAccessKeyId]",
	"secretAccessKey": "[YourSecretAccessKey]",
	"region": "[YourRegion]"
};


var client = easy.createClient(awsConfig);

client.getQueue("https://sqs.eu-west-1.amazonaws.com/123/queueName", function(err, queue){

	//returns an error if the queue doesn't exist

});

The awsConfig parameter is optional. If the argument is not provided it will default to the AWS settings in your environment. Even if you want to have your application pass in some AWS settings (like proxy settings) you can omit the Credentials as long as they are available in your environment.

Getting a single message

queue.getMessage(function(err, msg){

	console.log(msg.Body);

});

Deleting a single message

queue.getMessage(function(err, msg){

	//all good, delete the message

	queue.deleteMessage(msg, function(err){

	});

});

Sending a single message

//messages must be strings for now...
queue.sendMessage("my message body", function(err){


});

Using a QueueReader

It is common to have an application just sit and monitor a queue, process the message when it arrives, and then to continue to wait. For this activity, use a QueueReader.

var queueReader = queue.createQueueReader();

queueReader.on("message", function (message, context) {

		//process msg.Body here...
		context.deleteMessage(message);

});

queueReader.on("error", function (err) {

    queueReader.stop();

});

queueReader.start();

Please note, the previous interface with onReceipt, onEmpty, and onError will be deprecated in future versions. Please modify to use standard events.

About

Wrapper for SQS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 50.2%
  • TypeScript 49.8%