Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/mqstreams
MQ pub/sub as streams - based on mqemitter
https://github.com/mcollina/mqstreams
Last synced: about 1 month ago
JSON representation
MQ pub/sub as streams - based on mqemitter
- Host: GitHub
- URL: https://github.com/mcollina/mqstreams
- Owner: mcollina
- License: isc
- Created: 2014-02-28T12:54:19.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-05-09T22:57:11.000Z (over 8 years ago)
- Last Synced: 2024-11-01T12:42:23.323Z (about 2 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
mqstreams [![Build Status](https://travis-ci.org/mcollina/mqstreams.svg)](https://travis-ci.org/mcollina/mqstreams)
=================================================================Publish-Subscribe node streams style, based on
[mqemitter](http://github.com/mcollina/mqemitter).* Installation
* Basic Example
* API
* Licence & copyright```
$ npm install mqemitter mqstreams --save
``````js
'use strict'var mqemitter = require('mqemitter')
var mqstreams = require('mqstreams')
var emitter = mqstreams(mqemitter())
var through = require('through2')
var input = emitter.writable()
var output = emitter.readable('output/#')emitter
.readable('some/+')
.pipe(through.obj(function (msg, enc, callback) {
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' }
})
```## API
*
mqstreams
*emitter#readable()
*emitter#writable()
-------------------------------------------------------
### mqstreams(mqemitter)Extends the MQEmitter with the `readable()` and `writable()` methods.
-------------------------------------------------------
### emitter.readable([topic], [opts])Return
a [`Readable`](http://nodejs.org/api/stream.html#stream_class_stream_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 Stream3 interface.The `topic` parameter is passed to the
[`emitter.on`](https://github.com/mcollina/mqemitter#on) method.the returned object has the following method added:
`subscribe()`, `unsubscribe()`, `destroy()`.
#### emitter.readable#subscribe(topic)Subscribe to the given topic, which can also be an array of topics.
#### emitter.readable#unsubscribe(topic)Unsubscribe from the given topic, which can also be an array of topics.
#### emitter.readable#destroy()Close the stream, unsubscribing from all the topics.
This is aliased to `close()` for backwards compatibility.-------------------------------------------------------
### emitter.writable([opts])Return
a [`Writable`](http://nodejs.org/api/stream.html#stream_class_stream_writable)
stream in object mode that will pass any message to the
[`emitter.emit`](https://github.com/mcollina/mqemitter#emit) method.
This stream fully respect the Stream3 interface.## LICENSE
MIT