# nestjs-pubsub-transport

> Custom transport for Google PubSub for NestJS framework

Latest version **1.10.0** (published 2022-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-pubsub-transport
pnpm add nestjs-pubsub-transport
yarn add nestjs-pubsub-transport
bun add nestjs-pubsub-transport
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.10.0 |
| Published | 2022-10-17 |
| First published | 2021-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14.0.0 |
| Dependencies | 1 |
| Unpacked size | 27 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Max Dovhopolyi |
| Maintainers | tricky-max |
| Keywords | pubsub, google, transport, server, nest, nestjs |

## Links

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

## Dependencies (1)

- [error-to-json](https://npm.io/package/error-to-json.md) ^2.0.0

## 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.10.0 (latest) — 2022-10-17
- 1.9.2 — 2022-09-19
- 1.9.1 — 2022-09-19
- 1.9.0 — 2022-09-19
- 1.8.0 — 2022-09-16
- 1.7.2 — 2022-06-08
- 1.7.1 — 2022-06-08
- 1.7.0 — 2022-05-27
- 1.6.0 — 2022-05-24
- 1.5.0 — 2022-03-15
- 1.4.2 — 2021-11-25
- 1.4.1 — 2021-06-14
- 1.4.0 — 2021-06-14
- 1.3.2 — 2021-06-13
- 1.3.1 — 2021-06-13
- … 7 more at https://npm.io/package/nestjs-pubsub-transport/versions

## README

# nestjs-pubsub-transport

[![Deploy](https://github.com/mdovhopo/nestjs-pubsub-transport/workflows/build/badge.svg)](https://github.com/mdovhopo/nestjs-pubsub-transport/actions)
[![Coverage Status](https://coveralls.io/repos/github/mdovhopo/nestjs-pubsub-transport/badge.svg?branch=master)](https://coveralls.io/github/mdovhopo/nestjs-pubsub-transport?branch=master)

Custom transport for Google PubSub for NestJS framework

Installation:

```sh
npm i nestjs-pubsub-transport
```

## Examples

### install module

 ```ts
 @Module({
  imports: [
    PubsubTransportModule.forRootAsync({
      inject: [],
      useFactory: () => ({
        topic: 'topic-name',
        subscription: 'subscription-name',
        ackDeadline: 10, // optional
        maxMessages: 10, // optional
        getPattern: (msg: Message) => msg.attributes.yourPattern, // optional
        deserializeMessage: (msg: Message) => msg.data,
      }),
    }),
    SomeModule,
  ],
})
export class AppModule {
}
 ```

 ```ts
 @Module({
  imports: [
    PubsubTransportModule.forRoot({
      topic: 'topic-name',
      subscription: 'subscription-name',
      ackDeadline: 10, // optional
      maxMessages: 10, // optional
      getPattern: (msg: Message) => msg.attributes.yourPattern, // optional
      deserializeMessage: (msg: Message) => msg.data,
    }),
    SomeModule,
  ],
})
export class AppModule {
}
 ```

### Controller example

```ts
import { Controller } from '@nestjs/common';
import { MessagePattern, Payload } from '@nestjs/microservices';
import { PubSubInterceptor } from 'nestjs-pubsub-transport';

// Use interceptor, to correctly catch errors, otherwise transport will always 'ack' message
@UseInterceptors(PubSubInterceptor)
@Controller()
export class ClientsController {
  constructor() {
  }

  // Make sure that your methods in controllers does not return anything, it might break
  // error handling logic
  @MessagePattern('pattern')
  authorize(@Payload() data: AuthorizeClientMessage) {
    console.log('handle message', data);
  }
}
```

### Connect transport as microservice

```ts
  // connect pubsub transport
app.connectMicroservice({
  strategy: app.get(PubSubTransport),
});
```

### Start transport

```ts
  await app.startAllMicroservicesAsync();
```

Bootstrapped with: [create-ts-lib-gh](https://github.com/glebbash/create-ts-lib-gh)

This project is [Mit Licensed](LICENSE).

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