# mqstreams

> MQ pub/sub as streams - based on mqemitter

Latest version **1.0.0** (published 2016-05-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install mqstreams
pnpm add mqstreams
yarn add mqstreams
bun add mqstreams
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-05-09 |
| First published | 2014-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Matteo Collina |
| Maintainers | matteo.collina |
| Keywords | emitter, events, message queue, mq, publish, subscribe, pub, sub, readable, writable |

## Links

- npm: https://www.npmjs.com/package/mqstreams
- Repository: https://github.com/mcollina/mqstreams
- Homepage: https://github.com/mcollina/mqstreams#readme
- Issues: http://github.com/mcollina/mqstreams/issues
- npm.io page: https://npm.io/package/mqstreams

## Dependencies (2)

- [mqemitter](https://npm.io/package/mqemitter.md) ^2.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.1.2

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-05-09
- 0.1.0 — 2014-03-10
- 0.0.1 — 2014-03-09

## README

mqstreams&nbsp;&nbsp;[![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).

  * <a href="#install">Installation</a>
  * <a href="#basic">Basic Example</a>
  * <a href="#api">API</a>
  * <a href="#license">Licence &amp; copyright</a>

<a name="install"></a>
## Installation

```
$ npm install mqemitter mqstreams --save
```

<a name="basic"></a>
## Basic Example

```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

  * <a href="#mqstreams"><code>mqstreams</code></a>
  * <a href="#readable"><code>emitter#<b>readable()</b></code></a>
  * <a href="#writable"><code>emitter#<b>writable()</b></code></a>

-------------------------------------------------------
<a name="mqstreams"></a>
### mqstreams(mqemitter)

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

-------------------------------------------------------
<a name="readable"></a>
### 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()`.

<a name="readable-subscribe"></a>
#### emitter.readable#subscribe(topic)

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

<a name="readable-unsubscribe"></a>
#### emitter.readable#unsubscribe(topic)

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

<a name="readable-close"></a>
#### emitter.readable#destroy()

Close the stream, unsubscribing from all the topics.
This is aliased to `close()` for backwards compatibility.

-------------------------------------------------------
<a name="writable"></a>
### 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

---
_Source: https://npm.io/package/mqstreams · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
