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

tokki

v0.1.3

Published

A RabbitMQ/AMQP Handler

Downloads

17

Readme

Tokki

A RabbitMQ/AMQP Handler

Table of Contents

Installation

# Production
npm install tokki -P
# Development
npm install tokki -D

Quick start

Examples are stored in the examples folder.

Create a connection

const tokki require('tokki');
// or with TypeScript
import tokki from 'tokki'

// create a connection
const amqp = tokki({
  url: 'amqp://user:pwd@localhost:5672'
});

Using workers

The worker service distributes the events to the various workers. Each event only goes to one worker. See the example on RabbitMQ.

// trigger

const trigger = await amqp.worker({ name: 'worker-queue-name' });

// send a payload to queue
trigger.send({ message: 'imported' });

// consumer

const worker = await amqp.worker({ name: 'worker-queue-name' });

// or with error queue
const error = await amqp.worker({ name: 'error-queue-name' });
const worker = await amqp.worker({ name: 'worker-queue-name', errorService: error });

// Optionally, a schema ([JOI](https://github.com/hapijs/joi)) for the payload can also be passed as a parameter.

// define a consumer
worker.setConsumer(async (data) => {
  // data.payload.message = imported

  // ...

  // job is successful
  data.next();

  // or

  // job is failed (but requeue)
  data.defer();

  // or

  // job is failed
  data.discard();
});

Using publishers

The Publish Service distributes the events to all publishers. See the example on RabbitMQ.

const trigger = await amqp.publisher({ name: 'publish-queue-name' });

const publisher1 = await amqp.publisher({ name: 'publish-queue-name' });

// publisher with error queue
const error = await amqp.worker({ name: 'error-publish-queue-name' });
const publisher2 = await amqp.publisher({ name: 'publish-queue-name', errorService: error });

// Optionally, a schema ([JOI](https://github.com/hapijs/joi)) for the payload can also be passed as a parameter.

publisher1.setConsumer(async (data) => {
  // see worker section
  //
  // data.payload.message = imported
});
publisher2.setConsumer(async (data) => {
  // see worker section
  //
  // data.payload.message = imported
});

// send a payload to queue
trigger.send({ message: 'imported' });

Building

Compile the library from TypeScript to JavaScript.

The following command is available:

  • npm run build

    Builds the library

Tests

There are three types of tests:

  • Unit Tests

    These tests have no dependencies outside the tested file (exception: class inheritance). All dependencies are mocked.

    A test coverage of 100% should be achieved.

  • Integration Tests

    These tests have no dependencies outside the project. All dependencies in the package.json file are mocked. Small libraries, e.g. lodash or luxon, don't need to be mocked.

    A test coverage between 50% and 75% should be achieved.

  • Functional Tests

    These tests are performed with all dependencies and take a long time. External services, e.g. MySQL, will/must be provided via docker.

    No dependency should be mocked.

    A test coverage between 50% and 75% should be achieved.

The following commands are available:

| Command | Type | Description | | -------------------------------- | :---------: | ----------------------------------------------- | | npm run test | unit | Run all unit tests | | npm run test:watch | unit | Watching mode from unit test | | npm run coverage | unit | Creates a coverage report from unit test | | npm run test:integration | integration | Run all integration tests | | npm run test:integration:watch | integration | Watching mode from integration test | | npm run coverage:integration | integration | Creates a coverage report from integration test | | npm run test:functional | functional | Run all functional tests | | npm run test:functional:watch | functional | Watching mode from functional test | | npm run coverage:functional | functional | Creates a coverage report from functional test |

Prettier and Lint

Ensures that the code is formatted uniformly and that the coding standards are adhered to.

The following commands are available:

  • npm run prettier

    Changes the code formatting as defined in the Prettier setting.

  • npm run lint

    Checks if the lint rules are followed. It calls the prettier command first.