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

sqsumer

v1.1.0

Published

Worker to consume AWS SQS messages, built with Serverless and AWS Lambda in mind

Downloads

41

Readme

Sqsumer - AWS SQS worker

NPM version digitalmaas NPM downloads standardjs

Library to process messages from an Amazon SQS queue with an AWS Lambda worker function or your favorite other JavaScript environment. Based of Sebastian Müller's work on lawos.

Install

Sqsumer depends on AWS SDK for JavaScript in Node.js and bluebird.

$ > npm install bluebird aws-sdk sqsumer --save

API

🔷 constructor

Syntax

new Sqsumer(queueUrl, sqs[, messagesPerIteration])

Parameters

  1. queueUrl
    • Address of the target SQS queue
  2. sqs
    • Instance of SQS client from AWS SDK
  3. messagesPerIteration
    • Maximum number of messages received per iteration ([1, 10], default 10)

Return Value

An Sqsumer instance.

 

🔷 item

Syntax

instance.item(workerCallback)

Parameters

  1. workerCallback
    • Function that processes each received message.
      • Parameters
        1. message
          • A message from the target queue.
      • Returns
        • If it is a common function, it will be wrapped in a promise, where a return value will resolve it and a throw will rejected it. It can also return a promise, which will work as expected. If the promise is resolved, the message will be removed from the queue; otherwise, no action will be taken.

Return Value

A reference to of its instance, so calls can be chained.

 

🔷 work

Syntax

instance.work(stopConditionCallback)

Parameters

  1. stopConditionCallback
    • Function that is invoked in the end of each iteration.
      • Parameters
        1. metrics
          • Latest metrics from the current worker session.
      • Returns
        • If it is a common function, it will be wrapped in a promise, where a return value will resolve it and a throw will rejected it. It can also return a promise, which will work as expected. If the promise is resolved, the return value will be evaluated: if truthy, worker session ends; if falsy, worker session continues. If the promise is rejected, the worker session ends.

Return Value

A promise, which will be resolved with the worker session metrics.

Example

Assuming you're using AWS Lambda:

const SQS = require('aws-sdk/clients/sqs') // who needs it all?
const sqs = new SQS()

const Sqsumer = require('sqsumer')
const actualWork = require('./actualWork')

module.exports.handler = (event, context, done) => {
  new Sqsumer('https://sqs.eu-west-1.amazonaws.com …', sqs)
    .item(message => actualWork(message))
    .work(() => context.getRemainingTimeInMillis() < 1000)
    .then(metrics => {
      done(null, metrics)
    })
}

License

MIT License.
For the complete information, please refer to the license file.