/upring-pubsub

PubSub system built on top of UpRing

Primary LanguageJavaScriptMIT LicenseMIT

UpRingPubSub

npm version Build Status Coverage Status

PubSub system built on top of an UpRing consistent hashring. UpRingPubSub is consistently available, so it can lose messages when the topology changes. However, it is massively scalable.

See MQEmitter for the actual API.

js-standard-style

Install

npm i upring-pubsub --save

Usage

'use strict'

const UpRingPubsub = require('upring-pubsub')

const broker = UpRingPubsub({
  base: process.argv.slice(2)
})

broker.on('#', function (msg, cb) {
  console.log(msg)
  cb()
})

broker.upring.on('up', function () {
  console.log('copy and paste the following in a new terminal')
  console.log('node example', this.whoami())
})

var count = 0

setInterval(function () {
  count++
  broker.emit({
    topic: 'hello',
    count,
    payload: `from ${process.pid}`
  })
}, 1000)

API

new UpRingPubSub(opts)

All the options of UpRing and MQEmitter, combined.

UpRingPubSub specific options:

  • upring: an already initialized UpRing instance that has not already emitted 'up'

Acknowledgements

This project is kindly sponsored by nearForm.

License

MIT