RESTful publish/subscribe toolkit including broker, publisher and subscriber
npm install brokowskibrokowski  
===========
Known issues
RESTful publish/subscribe toolkit including broker, publisher and subscriber.
Brokowski has a RESTful pub/sub broker, which runs as a HTTP server. It receives subscriptions and events via a RESTful API. The events will be forwarded to the connected subscriber services.
Brokowski also includes publisher and subcriber modules, which offer simple APIs for RESTful event handling. They take care of setting up HTTP servers, connecting to the broker and sending/receiving events via the broker's RESTful API, making it easy to include pub/sub event handling into your apps. And since the broker runs on HTTP you can connect your own services via HTTP, too.
js
// start a broker server at http://192.168.0.1:6000
var Brokowski = require('brokowski').BrokowskiServer
, brokowski = new Brokowski({
port: 6000 // default: 3000
}).start();
// start a cluster of brokers at http://192.168.0.1:6000 (one server on each CPU core)
var Brokowski = require('brokowski').BrokowskiCluster
, brokowski = new Brokowski({port: 6000}).start();
// start the broker with default subscribers
new Brokowski({
port: 6000,
subscribers: [{
event: 'my-event',
method: 'GET',
hostname: '192.168.0.100',
port: 6002,
path: 'my-service'
}]
}).start();
`
subscriber server:
`js
// start a subscriber at http://localhost:6002/mysubscriber
var Sub = require('brokowski').Sub
, sub = new Sub({
port: 6002 // optional, default: 3000
name: 'mysubscriber', // mandatory
broker: 'http://192.168.0.1:6000' // mandatory
}).start();
sub
.get('my-event', function(data) { // resubscribing
if(data.coolstuff) console.log('GET my-event');
})
.post('my-event', function(data) { // resubscribing
if(data.coolstuff) console.log('POST my-event');
})
.put('my-event', function(data) { // resubscribing
if(data.coolstuff) console.log('PUT my-event');
})
.delete('my-event', function(data) { // resubscribing
if(data.coolstuff) console.log('DELETE my-event');
})
.subscribe({
event: 'my-other-event',
method: 'GET', / or 'POST' or 'PUT' or 'DELETE' /
hostname: '192.168.0.100', / default: 'localhost' /
port: 6002, / default: port provided to sub(options) /
path: 'my-service', / default: '/service-name/method/event' /
handler: function(data) {
console.log('GET my-other-event');
}
});
.resubscribe({
event: 'my-other-event',
method: 'GET',
handler: function(data) {
console.log('GET my-other-event');
}
});
.unsubscribe({
event: 'my-other-event',
method: 'GET',
handler: function(data) {
console.log('GET my-other-event');
}
});
`
publisher:
`js
var Pub = require('brokowski').Pub
, pub = new Pub({broker: 'http://192.168.0.1:6000'});
pub.send('my-event', {coolstuff: true});
`
RESTful API of the broker
Subscription parameters:
`js
{
method: 'GET', / or 'POST' or 'PUT' or 'DELETE' /
hostname: '192.168.0.100' ,
port: 6000,
path: 'subscriber-path'
}
`
$3
* method: POST
* url: `http://localhost:6000/subscribe/myevent`
* json: see the parameters
* returns 200 if everything is ok
* returns 400 if json is incomplete
* returns 500 if subscriber was subscribed to event
$3
All subscribers matching the given json will be removed before the new subscription.
* method: POST
* url: `http://localhost:6000/resubscribe/myevent`
* json: see the parameters
* returns 200 if everything is ok
* returns 400 if json is incomplete
$3
All subscribers matching the given json will be removed.
* method: POST
* url: `http://localhost:6000/unsubscribe/myevent`
* json: see the parameters
* returns 200 if everything is ok
* returns 500 if subscriber wasn't already subscribed to event
$3
* method: POST
* url: `http://localhost:6000/publish/myevent`
* json: any
* returns 200 if everything is ok
$3
Removes all subscriptions.
* method: GET
* url: `http://localhost:6000/clear`
* should return `200`
$3
* method: GET
* url: `http://localhost:6000/monitoring/alive`
* should return `200``