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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@crepesourcing/happn

v1.0.1

Published

Consume flu events through RabbitMQ

Readme

Library for happn

Happn connects a RabbitMQ exchange and listens for CREPE events (possibly generated using flu-rails) sequentially. Happn helps developers to create "Projectors" that define how to match and consume events.

This gem connects a single RabbitMQ queue and bind it automatically to its exchange. These bindings are defined by developers through "matchers" when loading projectors.

Requirements

  • Node.js >= 24
  • Tested with RabbitMQ 3.5.8

Installation

Using npm:

$ npm install --save @crepesourcing/happn

About queues

  • Happn consumes a single queue through the RabbitMQ's Topic Exchange Model.
  • If the queue does not exist when happn starts, it is created automatically.
  • When connecting a queue, please be careful that each connection parameter must match the existing queue's parameters. For instance, the value of x-queue-mode must match to avoid a PRECONDITION FAILED error.
  • All bindings between queues and their exchange are reset when starting Happn. Based on all the projectors that have been registered, Happn detects which events must be consumed and binds its queue to the exchange depending on these event matchers.

About projectors

A projector:

  • defines one or multiple matchers to detect which events must be consumed. Matchers can be declared using 4 event properties
    • emitter: e.g. "Facebook" or "MyInternalApi" ("all" means "all emitters")
    • kind: e.g. "entity_change" or "kind" ("all" means "all kinds")
    • name: e.g. "create country" or "request to destroy bunnies" ("all" means "all names")
    • status: e.g. "new" or "replayed" ("all" means "all statuses")
  • defines how to consume these events.

When a projector throws an Exception, Happn stops.

Usage

Start Up

Happn = require("@crepesourcing/happn").Happn
var happn = new Happn(logger)
var projectors = [...]; // the projector you've created
happn.init(projectors);
happn.start().then(function() {
  logger.info("Happn started.");
});

Define a Projector

A projector is an object that defines how to consume one or multiple types of events. This class must:

  • "extend" module Projector.
  • use its on method to declare which events to match and how to consume them. This must be done in a defineHandlers method.
const { Projector } = require("@crepesourcing/happn");

class LoggerProjector extends Projector {
  name() {
    return "LoggerProjector";
  }

  defineHandlers() {
    this.on("MyApplication", "all", "create country", "new", (event) => {
      console.log("A country has been created and generated an event with id " + event.id());
    });

    this.on("Api", "request", "all", "new", (event) => {
      console.log("This is a new request to the controller " + event.data["controller_name"]);
    });
  }
}

The same projector written in Coffeescript:

Projector = require("@crepesourcing/happn").Projector

class LoggerProjector extends Projector
  name: ->
    "LoggerProjector"

  defineHandlers: ->
    @on "MyApplication", "all", "create country", "new", (event) =>
      console.log("A country has been created and generated an event with id #{event.id()}")

    @on "Api", "request", "all", "new", (event) =>
      console.log("This is a new request to the controller #{event.data["controller_name"]}")

Overall configuration options

All options have a default value. However, all options can be overridden by setting up environment variables.

| Option | Default Value | Type | Required? | Description | Example | | ---- | ----- | ------ | ----- | ------ | ----- | | RABBITMQ_SCHEME | "amqp" | String | Required | Scheme to contact RabbitMQ's host. | "amqps" | | RABBITMQ_HOST | "localhost" | String | Required | RabbitMQ exchange's host. | "192.168.42.42" | | RABBITMQ_PORT | 5672 | Integer | Required | RabbitMQ exchange's port. | 1234 | | RABBITMQ_USER | "" | String | Required | RabbitMQ exchange's username. | "root" | | RABBITMQ_PASSWORD | "" | String | Required | RabbitMQ exchange's password. | "pouet" | | RABBITMQ_EXCHANGE_NAME | "events" | String | Required | RabbitMQ exchange's name. | "myproject" | | RABBITMQ_QUEUE_NAME | "happn-queue" | String | Required | The RabbitMQ queue to create, bind and consume. If the queue does not exist, it will be created at startup. | "my-queue" | | RABBITMQ_QUEUE_DURABLE | true | Boolean | Optional | Make the RabbitMQ's exchange durable or not. From RabbitMQ's documentation: "Durable exchanges survive broker restart whereas transient exchanges do not (they have to be redeclared when broker comes back online)." | false |

Development

Sources are written in CoffeeScript and compiled to JavaScript in dist/, which is the only code published to npm.

$ nvm use
$ npm ci
$ npm run build

Release

Releases are published to npm by GitHub Actions (.github/workflows/release.yml), only when a vX.Y.Z tag is pushed. Pushing a branch never publishes anything.

  1. Describe the changes in CHANGELOG.md and commit them (npm version requires a clean working tree).
  2. Bump the version, which creates the commit and the matching tag:
    $ npm version <patch|minor|major>
  3. Push the commit and the tag:
    $ git push --follow-tags

The published version is the one from package.json, so always create tags with npm version.