@steelbreeze/broker
Lightweight publish and subscribe using Server-Sent Events for node and express
Last updated a year ago by mesmo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @steelbreeze/broker 
SYNC missed versions from official npm registry.

broker

Lightweight publish and subscribe using Server-Sent Events for node and express

If you like broker, please star it...

Install

npm i @steelbreeze/broker

Usage

Server

To create a message broker server within an express application:

const express = require('express');
const broker = require('@steelbreeze/broker');

// create the express application
var app = express();

// create a message broker that provides the last message on subscription
var events = broker.server({lastMessage: true});

// bind the message broker to the /events base URL
app.use('/events', events);

// start the express application
app.listen(1024, 'localhost');

You can create multiple message broker servers and bind them to different base URLs in the same express application.

Subscriber (node)

To create a subscription:

const broker = require('@steelbreeze/broker');

// create a client to the message broker
var client = broker.client({host:'localhost', port: 1024, path: '/events'});

// subscribe to the devices topic on the /events broker
client.subscribe('devices', (message) => {
	console.log(`All devices: (${message.id}) ${message.data}`);
});

A single client can subscribe to multiple topics.

Publisher (node)

To create a subscription:

const broker = require('@steelbreeze/broker');

// create a client to the message broker
var client = broker.client({host:'localhost', port: 1024, path: '/events'});

// publish a message on the devices topic of the /events broker every second
var timer = setInterval( () => {
	client.publish('devices', `Hello at ${new Date()}`, onError);
}, 1000);

function onError() {
	clearInterval(timer);
}

Web clients

In addition to using the provided client, a browser's EventSource may be used to subscribe and an HTTP POST can be used to publish.

Note: for some browsers this may require an EventSource polyfill.

License

MIT License

Copyright (c) 2018 David Mesquita-Morris

Current Tags

  • 1.0.0-beta.14                                ...           latest (a year ago)

14 Versions

  • 1.0.0-beta.14                                ...           a year ago
  • 1.0.0-beta.13                                ...           a year ago
  • 1.0.0-beta.12                                ...           a year ago
  • 1.0.0-beta.11                                ...           a year ago
  • 1.0.0-beta.10                                ...           a year ago
  • 1.0.0-beta.9                                ...           a year ago
  • 1.0.0-beta.8                                ...           a year ago
  • 1.0.0-beta.7                                ...           a year ago
  • 1.0.0-beta.6                                ...           a year ago
  • 1.0.0-beta.5                                ...           a year ago
  • 1.0.0-beta.4                                ...           a year ago
  • 1.0.0-beta.3                                ...           a year ago
  • 1.0.0-beta.2                                ...           a year ago
  • 1.0.0-beta.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 14
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |