# nestjs-google-pubsub-microservices

> Subscribe to Google Cloud PubSub topics using NestJS's EventMessage handlers.

Latest version **0.1.3** (published 2023-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-google-pubsub-microservices
pnpm add nestjs-google-pubsub-microservices
yarn add nestjs-google-pubsub-microservices
bun add nestjs-google-pubsub-microservices
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2023-07-05 |
| First published | 2023-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Ko Yamaura |
| Maintainers | ko1103001 |
| Keywords | nestjs, nestjs pubsub, nestjs google pubsub, google pubsub, pubsub |

## Links

- npm: https://www.npmjs.com/package/nestjs-google-pubsub-microservices
- Repository: https://github.com/crallen/nestjs-google-pubsub
- Homepage: https://github.com/crallen/nestjs-google-pubsub#readme
- Issues: https://github.com/crallen/nestjs-google-pubsub/issues
- npm.io page: https://npm.io/package/nestjs-google-pubsub-microservices

## Dependencies (7)

- [rxjs](https://npm.io/package/rxjs.md) ^7.8.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^10.0.5
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^10.0.5
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@google-cloud/pubsub](https://npm.io/package/@google-cloud/pubsub.md) ^3.7.1
- [@nestjs/microservices](https://npm.io/package/@nestjs/microservices.md) ^10.0.5

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

- 0.1.3 (latest) — 2023-07-05
- 0.1.2 — 2023-07-05

## README

# nestjs-google-pubsub

Subscribe to Google Cloud PubSub topics using NestJS's EventMessage handlers.

## Installation

```
# NPM
npm install nestjs-google-pubsub

# Yarn
yarn add nestjs-google-pubsub
```

## Usage

The PubSubServer follows the same [microservice convention](https://docs.nestjs.com/microservices/basics) used by other NestJS integrations:

```typescript
import { NestFactory } from '@nestjs/core';
import { PubSubServer } from 'nestjs-google-pubsub';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    strategy: new PubSubServer({
      projectId: 'my-gcp-project',
      // other PubSub client options
      topics: {
        'my-topic': {
          subscriptionId: 'my-subscription'
        }
      }
    })
  });
  app.listen(() => console.log('Microservice is listening'));
}
bootstrap();
```

Next, set up a handler somewhere in your app:

```typescript
import { Message } from '@google-cloud/pubsub';
import { Controller } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';

@Controller()
export class MyController {
  @EventPattern('my-topic')
  async handleMyTopicEvent(data: Message) {
    // business logic
  }
}
```

## Configuration

The PubSubServer constructor takes in an options object that supports all of the same fields that the PubSub client supports. For more information on these options, visit the [PubSub documentation](https://googleapis.dev/nodejs/pubsub/latest/global.html#ClientConfig).

The only required option in the configuration is a map of topic IDs to subscription IDs. To be consistent with how other message queue systems work, the topic ID is specified in the `EventPattern` decorator. For PubSub, we also need the subscription ID. This can be specified in the `topics` field of the configuration object.

```typescript
const app = await NestFactory.createMicroservice(AppModule, {
  strategy: new PubSubServer({
    topics: {
      'my-topic': {
        subscriptionId: 'my-subscription'
      }
    }
  })
});
```

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