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

@ibrokethat/supermyx

v0.2.6

Published

supermyx is an oppionated rabbitmq wrapper around node-amqp

Downloads

4

Readme

supermyx

supermyx is a highly oppionated AMQP/RabbitMQ wrapper around node-amqp and implements two messaging patterns, work queues and publish subscribe.

Installation

$ npm install supermyx --save

Work Queue Example

A work queue uses a direct exchange and contains a single queue; each consumer pulls a single message off the queue in a round robin fashion; so load is distributed evenly amongst consumers.

Producer

const producer = require('supermyx')
  .queue('amqp://localhost:5672')
  .producer;

producer.publish('build/timeline', 'get me a timeline')
  .then(() => console.log('published message to exchange'))
  .catch(err) => console.error('error %s', err));

process.on('supermyx:log', (msg) => {
  console.log('%j', msg);
});

Consumer

const consumer = require('supermyx')
  .queue('amqp://localhost:5672')
  .consumer;

consumer.subscribe('build/timeline', (data, ack) => {
  console.log('%j', data);

  // Do work here
  const ok = true;

  if (ok) {
    // message processed successfully
    ack(false, false);
  } else {
    // dead letter this message
    ack(true);
  }
});

process.on('supermyx:log', (msg) => {
  console.log('%j', msg);
});

Work Queue Configuration

Supermyx will create an exchange and queue based on the routing key passed in, so each exchange has a single work queue.

Exchange:

build.timeline.workqueue

Queue:

build/timeline

Publisher confirms

The supermyx work queue producer uses the RabbitMQ extension publisher confirms, which ensures a message is delivered to RabbitMQ, we will Promise.reject if RabbitMQ returns an error when sending a message.

Acknowledgement

The supermyx work queue consumer is configured to use acks, which ensure a message when pulled from a queue is acknowledged before removing it from the queue. supermyx will only pull 1 message of the queue at a time.

Dead letter queue

supermyx will create a dead letter exchange/queue for each exchange/queue configured, in this format:

Exchange:

build.timeline.workqueue.dead

Queue:

build/timeline/dead

Calling ack(true) from a consumer will reject a message and push the message to a dead letter queue; ack(false) will not dead letter the message.

Heartbeats

Heartbeats are configured at 60 seconds.

Reconnects

Reconnects are supported using a linear strategy, at 120ms second intervals.

Durability

Exchanges, queues and messages are durable; messages will expire after 1 hour; if not consumed.

Publish Subcribe

PubSub uses a fanout exchange, all messages published to this exchange are routed to each consumer.

Producer

const producer = require('supermyx')
  .pubsub('amqp://localhost:5672')
  .producer;

producer.publish('notify', 'get me a timeline')
  .then(() => console.log('published message to exchange'))
  .catch((err) => console.error('error %s', err));

process.on('supermyx:log', (msg) => {
  console.log('%j', msg);
});

Consumer

const consumer = require('supermyx')
  .pubsub('amqp://localhost:5672')
  .consumer;

consumer.subscribe('notify', (data, ack) => {
  console.log('%j', data);

  // Do work here
  const ok = true;

  if (ok) {
    // message processed successfully
    ack(false, false);
  } else {
    // dead letter this message
    ack(true);
  }
});

process.on('supermyx:log', (msg) => {
  console.log('%j', msg);
});

Publish Subscribe Configuration

When a consumer starts up it will create a fanout exchange and a new queue, which is exclusive, and will auto delete when the consumer ends or restarts.

Exchange:

notify.pubsub

Queue:

amq.gen-YCFBmP1pgQF8cME9Uh90Lg

Heartbeats

Heartbeats are configured at 60 seconds.

Reconnects

Reconnects are supported using a linear strategy, at 120ms second intervals.

Publisher confirms

The supermyx pubsub producer uses the RabbitMQ extension publisher confirms, which ensures a message is delivered to RabbitMQ, we will Promise.reject if RabbitMQ returns an error when sending a message.

Durability

Exchanges, queues and messages are not durable.

Logging

supermyx will emit log messages at various intervals; so you can setup a handler listening to:

process.on('supermyx:log', (msg) => {
  console.log('%j', msg);
});

You can change the log emitter handler name, like so

const options = {
  log: 'my:log'
};

const consumer = require('supermyx')
  .pubsub('amqp://localhost:5672', options)
  .consumer;

process.on('my:log', (msg) => {
  console.log('%j', msg);
});