npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ya-sqs

v2.3.0

Published

Yet Another AWS SQS wrapper with pull (long polling), push, error management and promises.

Downloads

494

Readme

ya-sqs

Build Status Dependency Status devDependency Status

Yet Another AWS SQS wrapper with pull (long polling), push, error management and promises.

Install

npm install ya-sqs

Usage

var sqs = require('ya-sqs');

var queue = sqs.createQueue({
  aws: {
    region: 'eu-west-1',
    accessKeyId: '...',
    secretAccessKey: '...'
  },
  name: 'ya-sqs-test'
});

// Push message in the queue.
queue.push({foo: 'bar'}, function (err) {
  console.log('Message pushed.');
});

// Pull message.
queue.pull(function (message, next) {
  console.log('Message pulled.');
  next(); // Remove message from queue and pull next.
});

Example with promises

var sqs = require('ya-sqs');

var queue = sqs.createQueue({
  aws: {region: 'eu-west-1'},
  name: 'ya-sqs-test'
});

// Push message in the queue.
queue.push({foo: 'bar'}).then(function () {
  console.log('Message pushed.');
});

// Pull message.
queue.pull(function (message) {
  console.log('Message pulled.');
  return Promise.resolve(); // Remove message from queue and pull next.
});

sqs.createQueue(options)

Create a new queue. If you provide a name, the queue will be automatically created.

{object} options
{string} [options.name] Name of the queue
{string} [options.url] Url of the queue
{string} [options.aws] AWS config
{string} [options.waitTime=20] Polling time
{string} [options.formatter] Formatter (default JSON)
var queue = sqs.createQueue({
  url: 'https://sqs.eu-west-1.amazonaws.com/279100839409/ya-sqs-test',
  waitTime: 10,
  aws: {
    region: 'eu-west',
    sslEnabled: true
  }
});

queue.push(message, [cb])

Push a new message in the queue.

Promises:

queue.push('hello').then(function () {
  console.log('Message pushed.');
}, function (err) {
  console.log('Error during push.');
});

Callback:

queue.push('hello', function (err) {
  if (err) return console.log('Error during push.');
  console.log('Message pushed.');
});

queue.mpush(messages, [cb])

Push message using batch method.

Promises:

queue.mpush(['hello', 'world']).then(function () {
  console.log('Messages pushed.');
}, function (err) {
  console.log('Error during push.');
});

Callback:

queue.mpush(['hello', 'world'], function (err) {
  if (err) return console.log('Error during push.');
  console.log('Message pushed.');
});

queue.pull(handler, [options])

Pull message from the queue. When the promise returned is resolved or when next is called, the message will be remove and an other message will be pulled. If an error is sent, the error will be emitted and the message will not be removed.

Options:

@param {object} [options]
@param {number} [options.maxNumberOfMessages=10] Max number of messages

Promises:

queue.pull(function (message) {
  console.log('Message pulled.', message);
  return Promise.resolve();
});

Callback:

queue.pull(function (message, next) {
  console.log('Message pulled.', message);
  next();
});

queue.close([cb])

Stop pulling events, the promise is resolved when current messages have been processed.

queue.close().then(...);

Formatters

The default formatter for the queue is JSON, you can write a custom formatter for messages. To do it, please refer to the JSON formatter.

Example that specify a raw formatter (the message will not be formatted):

ws.createQueue({
  formatter: {
    format: function (message) {
      return Promise.resolve(message);
    },
    parse: function (message) {
      return Promise.resolve(message);  
    }
  }
})

Events

"error"

Emitted when ReceiveMessage command has an error, when a message can't be parsed and when you return an error in the "next" method.

queue.on('error', function (err) {
  // ...
});

"message pushed"

Emitted when a message is pushed. The message in argument is not formatted.

queue.on('message pushed', function (message) {
  // ...
});

"message received"

Emitted when a new message is received. The message in argument is not parsed.

queue.on('message received', function (message) {
  // ...
});

"message processed"

Emitted when a message is processed. The message in argument is not parsed.

queue.on('message processed', function (message) {
  // ...
});

License

MIT