# @superbalist/js-pubsub-manager

> A manager & factory for the js-pubsub package.

Latest version **3.0.1** (published 2018-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @superbalist/js-pubsub-manager
pnpm add @superbalist/js-pubsub-manager
yarn add @superbalist/js-pubsub-manager
bun add @superbalist/js-pubsub-manager
```

## 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 | 3.0.1 |
| Published | 2018-11-21 |
| First published | 2017-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 33.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Superbalist.com a division of Takealot Online |
| Maintainers | bradwhittington, mike-faut, zoidbergwill |
| Keywords | pubsub, google, cloud, redis |

## Links

- npm: https://www.npmjs.com/package/@superbalist/js-pubsub-manager
- Repository: https://github.com/Superbalist/js-pubsub-manager
- Homepage: https://github.com/Superbalist/js-pubsub-manager#readme
- Issues: https://github.com/Superbalist/js-pubsub-manager/issues
- npm.io page: https://npm.io/package/@superbalist/js-pubsub-manager

## Dependencies (6)

- [redis](https://npm.io/package/redis.md) ^2.7.1
- [@google-cloud/pubsub](https://npm.io/package/@google-cloud/pubsub.md) ^0.11.0
- [@superbalist/js-pubsub](https://npm.io/package/@superbalist/js-pubsub.md) ^3.0.0
- [@superbalist/js-pubsub-http](https://npm.io/package/@superbalist/js-pubsub-http.md) ^2.0.0
- [@superbalist/js-pubsub-redis](https://npm.io/package/@superbalist/js-pubsub-redis.md) ^3.0.0
- [@superbalist/js-pubsub-google-cloud](https://npm.io/package/@superbalist/js-pubsub-google-cloud.md) ^3.0.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2018-11-21
- 3.0.0 — 2017-07-18
- 2.0.2 — 2017-05-26
- 2.0.1 — 2017-05-23
- 2.0.0 — 2017-05-17
- 1.0.2 — 2017-05-15
- 1.0.1 — 2017-05-09
- 1.0.0 — 2017-05-08
- 0.0.1 — 2017-05-02

## README

# @superbalist/js-pubsub-manager

A manager & factory for the [js-pubsub](https://github.com/Superbalist/js-pubsub) package.

[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist)
[![Build Status](https://img.shields.io/travis/Superbalist/js-pubsub-manager/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/js-pubsub-manager)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![NPM Version](https://img.shields.io/npm/v/@superbalist/js-pubsub-manager.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub-manager)
[![NPM Downloads](https://img.shields.io/npm/dt/@superbalist/js-pubsub-manager.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub-manager)

This package adds a factory and manager on top of the [js-pubsub](https://github.com/Superbalist/js-pubsub) package.

The following adapters are supported:
* Local
* /dev/null
* Redis
* Google Cloud
* HTTP

## Installation

```bash
npm install @superbalist/js-pubsub-manager
```

The package has a default configuration which uses the following environment variables.
```
PUBSUB_CONNECTION=redis

REDIS_HOST=localhost
REDIS_PORT=6379

GOOGLE_CLOUD_PROJECT_ID=your-project-id-here
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/gcloud-key.json
GOOGLE_CLOUD_CLIENT_IDENTIFIER=null

HTTP_PUBSUB_URI=null
HTTP_PUBSUB_SUBSCRIBE_CONNECTION=redis
```

## Usage
```node
'use strict';

let pubSubManager = require('@superbalist/js-pubsub-manager');
let PubSubManager = pubSubManager.PubSubManager;
let PubSubConnectionFactory = pubSubManager.PubSubConnectionFactory;
let config = pubSubManager.config;

// add a custom connection to the config
config.connections.my_connection = {
  'driver': 'redis',
  'host': '192.168.0.1',
  'port': 6379,
  'db': 0
}

// create the connection manager
let factory = new PubSubConnectionFactory();
let manager = new PubSubManager(factory, config);

// get the default connection
let connection = manager.connection();

// publish a message
connection.publish('my_channel', {"first_name":"Matthew"});

// publish multiple messages to a channel
let messages = [
  'message 1',
  'message 2',
];
connection.publishBatch('my_channel', messages);

// subscribe to a channel
connection.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// publish a message over a custom or named connection
manager.connection('my_connection').publish('Hello World!');
```

## Adding a Custom Driver

Please see the [js-pubsub](https://github.com/Superbalist/js-pubsub) documentation  **Writing an Adapter**.

To include your custom driver, you can call the `extend()` function.

```node
'use strict';

let pubSubManager = require('@superbalist/js-pubsub-manager');
let PubSubManager = pubSubManager.PubSubManager;
let PubSubConnectionFactory = pubSubManager.PubSubConnectionFactory;
let config = pubSubManager.config;

// create the connection manager
config.connections.custom_driver = {
  // add custom config here
};
let factory = new PubSubConnectionFactory();
let manager = new PubSubManager(factory, config);

manager.extend('custom_driver', (config) => {
  // your callable must return an object which implements the https://github.com/Superbalist/js-pubsub/blob/master/src/PubSubAdapterInterface.js interface.
  return new MyCustomPubSubDriver(config);
});

// get an instance of your connection using a custom driver
let connection = manager.connection('custom_driver');
```

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