Skip to content

maboiteaspam/stream-message-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stream-message-router

A stream to route messages given their type.

Install

npm i maboiteaspam/stream-message-router --save-dev

Usage

var flower = require('flower')
var messageRouter = require('stream-message-router')

var streamA = flower();

var streamB = messageRouter('hello');       // stream-message-route is a stream which push only
var streamC = messageRouter('goodbye');     // the messages{message: type} matching given value.

streamA.pipe(streamB);                      // streamA will pipe many kind of messages,
streamA.pipe(streamC);                      // but streamB and streamC routes only specific
                                            // message types.
streamB.on('data', function (d) {
  console.log('streamB %j', d);
})

streamC.on('data', function (d) {
  console.log('streamC %j', d);
})

streamA.on('data', function (d) {
  console.log('streamA %j', d);
})

streamA.write({                             // write some messages Object {
  message : 'hello',                        //    type: the message type
  body    : 'the world'                     //    body: the message body
});                                         // }
streamA.write({
  message : 'goodbye',                      // another kind of message.
  body    : 'the world'
});

Read more

You can see it in action in npi

About

A stream to route messages given their type

Resources

Stars

Watchers

Forks

Packages

No packages published