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

bk-rabbitmq-pubsub

v0.2.0

Published

Library for rabbitmq and use pubsub service

Downloads

3

Readme

bk-rabbitmq-pubsub

This is a very opinionated abstraction over amqplib to help simplify the implementation of PubSub messaging patterns on RabbitMQ.

!IMPORTANT! - bk-rabbitmq-pubsub needs nodejs >= 8.x.

Features:

  • Publish event on a channel with data
  • Subscribe event from a channel and receive data
  • Attempt to gracefully handle lost connections and channels
  • Connections have a backoff policy of exponential delay randomized: ~1s, ~2s, ~4s, ~8s then stable at ~8s, ~8s...

Installation

npm install bk-rabbitmq-pubsub

Getting started

const RabbitmqPubSub = require('bk-rabbitmq-pubsub');

const pubsub = new RabbitmqPubSub();

// subscribe on the channel myEvent
pubsub.subscribe('myEvent', (data) => {
	console.log(data);
})

// publish event with data on channel MyEvent
pubsub.publish('myEvent', data);

API Reference

new RabbitmqPubSub(options)

Return a new RabbitmqPubSub pubsub client. options are :

  • url : URL to connect to RabbitMQ (default : amqp://guest:guest@localhost:5672/)
  • logLevel : Log level (default : info)
  • logName : Log name for Bunyan = (default : RabbitmqRPC)
  • exchangeName : Exchange name for handle RPC request (default : RabbitmqRPC)
  • log : Custom log instance (require to implement function trace, debug, info, warn and error)
  • subscribeQueueName : The name for the subscribeQueue, by default it's generated

{client} publish(channelName, data)

Subscribe on a channel. options are :

  • channelName : Name of the channel to subscribe. (throw an error if undefined or null)
  • data : Data send with the event for the subscribers.

{client} subscribe(channelName, listener)

Subscribe on a channel. options are :

  • channelName : Name of the channel to subscribe. (throw an error if undefined or null)
  • listener : The function call when an event arrive. The function take one arg whose is the data send by the publisher. This method return a number. This number is the subscription ID

{client} unsubscribe(channelName, listener)

Unsubscribe on a channel the specific listener. options are :

  • channelName : Name of the channel to unsubscribe. (throw an error if undefined or null)
  • listener : The listner function to unsubscribe.

{client} unsubscribe(subscriptionId)

Unsubscribe a specific subscription ID. options are :

  • subscriptionId : Id of the subscription.

{client} unsubscribeAll(channelName)

Remove all listener for a specific channel. options are :

  • channelName : Name of the channel to unsubscribe all function. (throw an error if undefined or null)

Contributing

First off, thanks for your interest and for wanting to contribute! PRs with insufficient coverage, broken tests or deviation from the style will not be accepted.

Run tests

# With docker
npm run build-image #to build rabbitmq Image
npm run start-image #to start rabbitmq on localhost
# Or provide your own local rabbitmq install

# run tests
npm test

# run lint
npm run lint

# run coverage
npm run coverage

TODO

  • Add better coverage test (unsubscribe, unsubscribeAll, ...)
  • Add better support for lost connection
  • ...

License

MIT License

Copyright (c) 2017 Beekast