# @web-artisans/gcp-subscriber

> A subscription helper for Google Cloud Pub/Sub.

Latest version **1.1.2** (published 2016-11-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install @web-artisans/gcp-subscriber
pnpm add @web-artisans/gcp-subscriber
yarn add @web-artisans/gcp-subscriber
bun add @web-artisans/gcp-subscriber
```

## 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.1.2 |
| Published | 2016-11-08 |
| First published | 2016-06-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dan Cowell |
| Maintainers | dfcowell, webartisans |
| Keywords | gcp, pubsub, google cloud, subscriber |

## Links

- npm: https://www.npmjs.com/package/@web-artisans/gcp-subscriber
- Repository: https://bitbucket.org/web-artisans/gcp-subscriber
- Homepage: https://bitbucket.org/web-artisans/gcp-subscriber#readme
- npm.io page: https://npm.io/package/@web-artisans/gcp-subscriber

## 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.1.2 (latest) — 2016-11-08
- 1.1.1 — 2016-11-08
- 1.1.0 — 2016-10-23
- 1.0.5 — 2016-10-23
- 1.0.4 — 2016-06-28
- 1.0.3 — 2016-06-28
- 1.0.1 — 2016-06-28
- 1.0.0 — 2016-06-28

## README

# Google Cloud Platform Subscriber #

This project is a simple, lightweight helper library for Google Cloud Pub/Sub subscription management.

## How do I get set up? ##

1. `npm install --save @web-artisans/gcp-subscriber`
2. `const subscriber = require('@web-artisans/gcp-subscriber')(pubsub, logger);`

## Usage ##

### Message Acknowledgement (acks) ###

If the supplied `onMessage` handler returns a Promise, the subscriber can ack the message automatically when the handler completes successfully. If not, you must acknowledge the message yourself in the `onMessage` handler function.

By default, errors are not acknowledged.

### subscriber.map ###

The map function takes an object whose keys are valid topic names and whose attributes are objects containing `onMessage` and `onError` handlers. For example:

```javascript
const subscriber = require('@web-artisans/gcp-subscriber')(pubsub, logger);

let subscriptions = {
    console-log: {
        onMessage: function(message) {
            console.log(message);
            message.ack(); //Manually ack since we don't return a promise
        },
        onError: function(error) {
            throw error;
        }
    },
    database-log: {
        onMessage: function(message) {
            return db.table('log').insert({message}); //No ack required here since insert returns a Promise.
        },
        onError: function(error) {
            throw error;
        }
    }
};

subscriber.map(subscriptions);

```

### Who do I talk to? ###

* Dan Cowell <dan@webartisans.com.au>

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