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

qball

v1.1.0

Published

Library which simplifies SQS queue processing

Downloads

6

Readme

Qball

What is Qball?

Qball is a library which simplifies processing AWS SQS queues. Normally you need to obtain queue urls, read from a queue, handle the messages, and delete the messages from the queue after you have processed the message successfully. Instead, at a high level, with Qball all you need to do is initialize it and tell it what function you want to process your queue messages.

Installation

  • You will need to install the qball library npm install qball --save
  • You will also need to install the aws-sdk-library npm install aws-sdk --save

Usage

Example

The following is a basic example configuration to get up and running. It will read messages from the queue "my-queue-name" which is owned by AWS account "123456789" 5 messages at a time every 10 seconds. For each message, it will log out to the console and then delete the message from the queue.

let AWS = require('aws-sdk'); // Include aws-sdk in your module
const qball = require('qball'); // Include qball in your module
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_KEY;
const region = 'us-east-1';
const AWS_ACCOUNT_ID = '123456789';
const numMessagesToRead = 5;
const pollingInterval = 10000;
AWS.config.update({ accessKeyId, secretAccessKey, region });

let qb = init(AWS, AWS_ACCOUNT_ID, 'my-queue-name', numMessagesToRead, pollingInterval); // Initialize qball

function handler (msg) { console.log(msg); return msg; } // Define a handler that will process each message read from the queue

qb.start(handler); // Start polling

In the above example, the message gets removed from the queue because the message is returned from the handler function. There is an second argument passed to the handler as well, a function, which you can invoke to indicate that you are done processing the message and wish it to be deleted. An example of this would be:

function handler (message, delMsg) {
  console.log(message);
  delMsg();
}

This library is also Promise friendly, so if you handler is a Promise chain you can return the message at the end of the chain, or invoke the delete message argument all the same.

API Reference

init

The only function exported by the Qball module.

Syntax

init(AWS, accountId, queueName, maxMessages, interval)

Parameters

AWS (object) an instance of the aws-sdk library

accountId (string) the value of the target queue's AWS account ID

queueName (string) the name of the target queue

maxMessages (integer) (defaults to 10) the number of messages to be read from the queue at once from 1 - 10

interval (integer) (defaults to 3000) how often the queue should be polled in milliseconds

Return Value

An API object with start and stop methods


start

Method of the API object returned by the init start and stop functions. Begins polling the configured queue.

Syntax

init(...).start(handler)

Parameters

handler (function) processes queue messages. Accepts two arguments: message and (optional) deleteMessage function

Return Value

A Promise, the value of the argument passed to the next .then() function is an API object with start and stop methods


stop

Method of the API object returned by the init start and stop functions. Stops polling the configured queue.

Syntax

init(...).stop()

Parameters

none

Return Value

A Promise, the value of the argument passed to the next .then() function is an API object with start and stop methods