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

rabbi

v1.25.0

Published

Build more reactive services better, faster, with more smiles.

Downloads

453

Readme

Rabbi

Build Better Typescript Services Faster With More Smiles

Commitizen friendly

Installation

Typescript and ts-node are required in your PATH to run rabbi apps.

npm install -g rabbi
Publishing Messages

First install rabbi into your typescript app:

npm install --save rabbi

Once connected to the amqp server cluster any application component may publish messages the exchange with a routing key and a json object

import { publish } from 'rabbi'

const exchange = 'midasvalley'

const routingkey = 'lease.created'

const json = {
  lessor: 'Dan',
  lessee: 'Jan',
  term: {
    period: 'month',
    number: 12
  },
  price: {
    currency: 'XBT',
    value: 1
  }
}

await publish(exchange, routingkey, json)

The above json will be automatically serialzed into a binary buffer and published to all listeners within the midasvalley exchange interested in the topic lease.created. These values are simply demo values.

Basic Actors Usage

Rabbi uses a directory and file naming convention to speed up writing and deploying new apps based on the reactive messaging and actor model.

Command Line

All actors should be under directories such as ./actors/{actor_name}/actor.ts.

/my/app/directory> rabbi start

Programmatic Use

All actors should be under directories such as ./{actor_name}/actor.ts.

import { startActorsDirectory } from 'rabbi';

startActorsDirectory(__dirname);


# Bunnies

Microservices Actor Toolchain for RabbitMQ

Build more services faster, better and with more smiles.

Extracted out of patterns used in my work on a multitute of live systems.

Simplifies an abstracts the creation of actors that respond to messages received
via AMQP.

Each actor maintains its own single queue of messages from which it pulls and
reacts to messages.

Sane defaults for managing amqp state make previously tedious code warm and
fuzzy, like a bunny.

## Architecture

According to AMQP best practices bunnies will connect a single socket to
the AMQP server provided by the AMQP_URL environment variable. This singleton
connection is used automatically when starting all actors, unless another
connection is specified explicitly.

You can also get a handle on the singleton connection by running

import { getConnection } from 'bunnies';

let connection = await getConnection();


`getConnection` will always return a single connection reused by all callers in
a given process.


## Library

Each actor consumes messages from a single rabbitmq queue. On startup the
actor will establish connection with your AMQP server, assert the specified
exchange and queue, and bind the queue to the exchange with the routing key.

Usage

import { Actor, log } from 'bunnies';

import { connect } from 'amqplib';

(async () => {

// connects to AMQP_URL environment variable

let actor = Actor.create({

exchange: 'orders',

routingkey: 'ordercreated',

queue: 'printorderreceipt'

});

await actor.start(async (channel, msg) => {

log.info('print order receipt', msg.content.toString());

await channel.ack(msg);

log.info('message acknowledged', msg.content.toString());

});

// publish example message with order uid as content

let buffer = new Buffer('cf9418e8-eb0f-4c7e-88a3-4aca045a30f2');

await actor.channel.publish('orders', 'ordercreated', buffer);

})();


#### Re-Using An Existing AMQP Connection

It may not be idea to connect a separate TCP socket for every single actor.
Instead, optionally provide an `amqp.Connection` when creating Actor.

import { connect, Connection } from 'amqplib';

let connection: Connection = await connect();

let actor = Actor.create({

exchange,

routingkey,

queue,

connection

})


The above will still create a new channel but will re-use the existing
connection.

## Events

Each actor is also an Event Emitter, emitting the following events:

- exchange.created
- queue.created
- binding.created

- amqp.connected
- amqp.disconnected

- message.received
- message.acked
- message.nacked

- error

## File System

Actors are exported as javascript modules. Each module must export an Actor
which implements the bunnies.Actor interface.

## Command Line Tool

Microservices can be run one or more at a time from the command line using the
`bunnies` command.


To run all actors

sh> bunnies --dir=./actors

sh> bunnies -a actors/matcher.js -a actors/rpc.js -a actors/websocket.js
sh> bunnies -bind universalgoldtrust|payments|ugt.payments \
            -queue ugt.payments \
            -exec process_payments.sh \
            -cleanup