Git Product home page Git Product logo

sqs's Introduction

sqs

A message queue using Amazon Simple Queue Service.

npm install sqs

Usage is simple

var sqs = require('sqs');

var queue = sqs({
	access:'my-aws-access-key',
	secret:'my-aws-secret-key',
	region:'us-east-1' // defaults to us-east-1
});

// push some data to the test queue
queue.push('test', {
	some:'data'
}, function () {
	// complete
});

// 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
	            // calling the callback will also delete the message from the queue
});

API

var queue = sqs(options)

Create a queue instance. Available options are

  • options.access - Your AWS access key (required)
  • options.secret - Your AWS secret key (required)
  • options.region - The AWS region for the queue. Defaults to us-east-1
  • options.namespace - Prefix all queues with namespace. Defaults to empty string.
  • options.https - If true use https. Defaults to false.
  • options.raw - If true it doesn't parse message's body to JSON. Defaults to false.
  • options.proxy - If set to a URL it will overwrite the default AWS SQS url.

Some of the options can be configured using env vars. See below for more.

queue.push(name, message, [callback])

Push a new message to the queue defined by name. If the queue doesn't exist sqs will create it. Optional callback called once request is completed.

queue.pull(name, [workers=1], onmessage)

Pull messages from the queue defined by name.

The pull flow is as follows:

  1. A message is pulled and is passed to onmessage(message, callback)
  2. You process the message
  3. Call callback when you are done and the message will be deleted from the queue.
  4. Goto 1

If for some reason the callback is not called amazon sqs will re-add the message to the queue after 30s.

Delete a queue.

queue.delete(name, [callback])

Fault tolerance

Both pull and push will retry multiple times if a network error occurs or if amazon sqs is temporary unavailable.

Env config

You can use env variables to configure sqs as well

SQS_ACCESS_KEY=my-access-key
SQS_SECRET_KEY=my-secret-key
SQS_REGION=us-east-1

In your application you can just call an empty constructor

var queue = sqs();

This is very useful if you dont want to hardcode your keys in the application.

sqs's People

Contributors

mafintosh avatar cladera avatar joshuakarjala avatar justinffs avatar marcusberner avatar nherment avatar roryrjb avatar torarvid avatar barwin avatar kapeels avatar tphummel avatar

Watchers

James Cloos avatar Zachary Nevin avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.