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');
var app = express();
app.use('/events', broker.server({lastMessage: true}));
app.listen(1024, 'localhost');
You can create multiple message broker servers and bind them to different base URLs.
Subscriber
To create a subscription:
const broker = require('@steelbreeze/broker');
var client = broker.client({host:'localhost', port: 1024, path: '/events'});
client.subscribe('devices', (message) => {
console.log(`devices: ${message}`);
});
A single client can subscribe to multiple topics.
Publisher
To create a subscription:
const broker = require('@steelbreeze/broker');
var client = broker.client({host:'localhost', port: 1024, path: '/events'});
setInterval( () => {
client.publish('devices', `Hello devices at ${new Date()}`);
}, 1000);
License
MIT License
Copyright (c) 2018 David Mesquita-Morris