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

@joevalim/queue

v1.5.7

Published

Simple queue based on Redis for Docker Demo

Downloads

1

Readme

npm (scoped) node (scoped) Travis

@subfuzion/queue

This is a simple queue package intended for a demo application used for educational purposes.

It provides a Producer class for enqueueing messages and a Consumer class for dequeueing them.

The queue is implemented using Redis and this package provides a trivial wrapper over the ioredis client for Node. The wrapper essentially provides a minimal facade for using a simple queue, and also serves to illustrate how to use and test basic Redis operations using ES2017 async/await support now available natively in Node.js.

This package is inspired by the existing Docker Example Voting App. The existing app is an excellent example of a real world polyglot application, demonstrating containerized processes created from a number of different programming languages. This package is intended to support a simpler version of the voting application that only uses Node.js and modern JavaScript that some developers may find a bit easier to follow while trying to understand how the application actually works.

Testing

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 @subfuzion/queue

Add the dependency to your package:

npm:

$ npm install @subfuzion/queue

yarn:

$ yarn add @subfuzion/queue

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.