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

@subfuzion/queue

v1.5.6

Published

Simple queue based on Redis for Docker Demo

Downloads

11

Readme

npm (scoped) node (scoped) Travis

@subfuzion/queue

This is a simple Node.js queue library package that provides a Producer class for enqueueing messages and a Consumer class for dequeueing them. The queue is backed by Redis and this package provides a trivial wrapper over the ioredis client for Node.js. This package uses ES2017 async/await support now available natively in Node.js.

Testing

The easiest way is to test using Docker Compose.

Testing with Docker Compose

The following will build an image for running the tests under test/test.js and then start the environment declared in ./docker-compose.test.yml.

$ docker-compose -f ./docker-compose.test.yml run sut

If you make changes to any of the Node.js sources, rebuild the test image with the following command:

$ docker-compose -f ./docker-compose.test.yml build

To view logs, run:

$ docker-compose -f ./docker-compose.test.yml logs

When finished with tests, run:

$ docker-compose -f ./docker-compose.test.yml down

Testing without Docker Compose

Redis needs to be available before running tests. The tests default to port 6379 on localhost, but host and port can be overridden by setting HOST and PORT environment variables.

If you have Docker installed, you can easily start Redis with the default values by running the following command:

$ docker run -d -p 6379:6379 --name queue redis

This will run a redis container named queue in the background with port 6379 on your system mapped to the exposed port 6379 in the container.

To run the tests, enter the following:

$ npm test

When finished, you can remove the running container from your system with:

$ docker rm -f queue

Using the @subfuzion/queue package with your own Node.js packages

Add the dependency to your package:

npm:

$ npm install @subfuzion/queue

yarn:

$ yarn add @subfuzion/queue

Create a Producer or Consumer object

Require the package in your module:

const Producer = require('@subfuzion/queue').Producer;
const Consumer = require('@subfuzion/queue').Consumer;

Create a new instance

var producer = new Queue([options])
var consumer = new Queue([options])

options is an optional object that defaults to the values in lib/defaults.js for any missing properties.

const config = {
  host: 'queue',
  port: 6379
};

There is a Queue helper static method that will create the configuration that can be overridden by environment variables:

let defaults = {};
// explicit defaults will override environment variables, environment overrides internal defaults
let config = Queue.createStdConfig(defaults);
let p = new Producer(topic, config);
let c = new Consumer(topic, config);

If any of the following environment variables are defined, then the values will override the default values. Any values explicitly supplied in the config object will override the environment.

QUEUE_URI - valid redis connection URI
otherwise:
  QUEUE_HOST - hostname for the redis server
  QUEUE_PORT - port that redis is listening on

Enqueueing Messages

var p = new Producer(topic [, config])
await p.send(message)
// when finished with the producer:
await p.quit()

where topic should be the queue topic and config is an optional object that can have host and port values.

Dequeueing Messages

var c = new Consumer(topic [, config])
let message = await c.receive(topic)
// when finished with the consumer: 
await c.quit()

where topic and config are the same as described previously.

Note that the receive method blocks until there is a message ready to be retrieved from the queue. The method will return null if the connection is closed (by calling quit) while it is waiting.

Closing Connections

You should always call quit on producers and consumers to ensure connections are gracefully closed on both the client and server sides.