mqstreams

MQ pub/sub as streams - based on mqemitter

mqstreams  

Publish-Subscribe node streams style, based on mqemitter.

$ npm install mqemitter mqstreams --save

var mqemitter = require('mqemitter')
  , mqstreams = require('mqstreams')
  , emitter = mqstreams(mqemitter())
  , through = require('through2')
  , input = emitter.writable()
  , output = emitter.readable('output/#')
 
emitter.readable('some/+')
       .pipe(through.obj(function(msgenccallback) {
           msg.topic = 'output/' + msg.topic
           this.push(msg)
           callback()
         }))
       .pipe(emitter.writable())
 
input.write({ topic: 'some/food', type: 'greek' })
input.write({ topic: 'some/startup', type: 'instasomething' })
input.end({ topic: 'some/dev', type: 'matteo' })
 
 
output.on('data', function(msg) {
  console.log(msg)
 
  // OUTPUT: 
  // { topic: 'output/some/food', type: 'greek' } 
  // { topic: 'output/some/startup', type: 'instasomething' } 
  // { topic: 'output/some/dev', type: 'matteo' } 
})

Extends the MQEmitter with the readable() and writable() methods.


Return a Readable stream in object mode that will include all emitter messages that match the given topic. The opts parameter is passed through to the Stream constructor. This stream fully respect the Stream2 interface.

The topic parameter is passed to the emitter.on method.

the returned object has the following method added: subscribe(), unsubscribe(), close().

Subscribe to the given topic, which can also be an array of topics.

Unsubscribe from the given topic, which can also be an array of topics.

Close the stream, unsubscribing from all the topics.


Return a Writable stream in object mode that will pass any message to the emitter.emit method. This stream fully respect the Stream2 interface.

Copyright (c) 2014, Matteo Collina hello@matteocollina.com

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.