Snurra Broker is a message bus with a stream interface. Below is an example on how to interact with it. Snurra plays very nicely with libraries like highland.js (http://highlandjs.org/), but Snurra Broker does not depend on it - snurra creates plain vanilla node streams, and will work with any stream library.
_ = require 'highland'
Broker = require 'snurra-broker'
broker = new Broker()
# Calling the broker with a string (a channel name), creates a
# through stream, which when written to ...
broker('add order').write
sku: "AZDTF4346",
qty: 21
# ... will dispatch the same message to all siblings:
_(broker('add order'))
.map (order) ->
friendlyName: order.sku + " (" + order.qty + " pieces)"
.pipe broker 'render order',
metadata1: 'hello'
metadata2: 'world'
_(broker.log).map (entry) -> console.log JSON.stringify entry
{
channel: 'add order',
data: {
sku: 'AZDTF4346',
qty: 21
}
},
{
channel: 'render order',
data: {
friendlyName: 'AZDTF4346 (21 pieces)'
},
metadata: {
metadata1: 'hello',
metadata2: 'world'
}
}