# @algoan/nestjs-google-pubsub-microservice

> A GooglePubSub transport strategy with NestJS Microservice

Latest version **3.2.0** (published 2026-09-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @algoan/nestjs-google-pubsub-microservice
pnpm add @algoan/nestjs-google-pubsub-microservice
yarn add @algoan/nestjs-google-pubsub-microservice
bun add @algoan/nestjs-google-pubsub-microservice
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2026-09-24 |
| First published | 2020-04-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 248 |
| Author | Charles Coeurderoy |
| Maintainers | algoanbot, fabong |
| Keywords | nodejs, typescript, nestjs, microservice, google-pubsub |

## Links

- npm: https://www.npmjs.com/package/@algoan/nestjs-google-pubsub-microservice
- Repository: https://github.com/algoan/nestjs-components
- Homepage: https://github.com/algoan/nestjs-components/tree/master/packages/google-pubsub-microservice#readme
- Issues: https://github.com/algoan/nestjs-components/issues
- npm.io page: https://npm.io/package/@algoan/nestjs-google-pubsub-microservice

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.2.0 (latest) — 2026-09-24
- 3.1.4 — 2025-06-11
- 3.1.3 — 2024-09-16
- 3.1.2 — 2023-12-11
- 3.1.1 — 2023-11-10
- 3.1.0 — 2023-06-17
- 3.0.9 — 2023-02-24
- 3.0.8 — 2023-02-02
- 3.0.7 — 2023-01-31
- 3.0.6 — 2022-11-19
- 3.0.5 — 2022-11-19
- 3.0.4 — 2022-07-26
- 3.0.3 — 2022-05-19
- 3.0.2 — 2022-01-07
- 3.0.1 — 2021-10-24
- … 15 more at https://npm.io/package/@algoan/nestjs-google-pubsub-microservice/versions

## README

<p align="center">
  <a href="http://nestjs.com"><img src="https://nestjs.com/img/logo_text.svg" alt="Nest Logo" width="320" /></a>
</p>

<p align="center">
  A <a href="https://github.com/nestjs/nest">Nest</a> Google PubSub Microservice.
</p>

# NestJS Google Cloud PubSub Micro-service

A custom [NestJS Microservice](https://docs.nestjs.com/microservices/basics) transport strategy using [Google Cloud PubSub](https://cloud.google.com/pubsub/docs).

## Installation

```bash
npm install --save @algoan/pubsub @algoan/nestjs-google-pubsub-microservice
```

## Usage

To start a new Google Cloud PubSub server:

**Server setup**:

```typescript
// main.ts
import { GooglePubSubOptions } from '@algoan/pubsub';
import { INestMicroservice } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { GCPubSubServer } from '@algoan/nestjs-google-pubsub-microservice';
import { AppModule } from './app.module';

async function bootstrap() {
  const options: GooglePubSubOptions = {
    projectId: 'test',
    subscriptionsPrefix: 'test-app',
  }

  const app: INestMicroservice = await NestFactory.createMicroservice(AppModule, {
    strategy: new GCPubSubServer(options)
  })

  await app.listen();

  console.log('Server running!')
}
bootstrap()
```

**Controller**:

```typescript
import { EmittedMessage } from '@algoan/pubsub';
import { Controller } from '@nestjs/common';
import { EventPattern, Payload } from '@nestjs/microservices';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  /**
   * Handle the test event
   * @param data Payload sent
   */
  @EventPattern('test_event')
  public async handleTestEvent(@Payload() data: EmittedMessage<{ hello: string }>): Promise<void> {
    /**
     * Handle data emitted by Google PubSub
     */
    this.appService.handleTestEvent(data);
  }
}
```

### EventPattern extras

You can add [`ListenOptions`](https://github.com/algoan/pubsub#pubsublistenevent-opts) to the subscription by adding `extras` to the `EventPattern` decorator. For example, if you want a different topic name:

```typescript
/**
  * Handle the test event
  * @param data Payload sent
  */
@EventPattern('test_event', { topicName: 'different_topic' })
public async handleTestEvent(@Payload() data: EmittedMessage<{ hello: string }>): Promise<void> {
  /**
    * Handle data emitted by Google PubSub
    */
  this.appService.handleTestEvent(data);
}
```

When the application will start and look for event patterns, it will get or create the `different_topic` topic from Google Cloud.

## API

This module uses [@algoan/pubsub](https://github.com/algoan/pubsub) library which by default automatically acknowledges emitted messages.

### `GCPubSubServer(options)`

Create a new Server instance of Google PubSub. It retrieves all message handlers patterns and creates [subscriptions](https://cloud.google.com/pubsub/docs/pull).

- `options`: Algoan PubSub options. More information [here](https://github.com/algoan/pubsub/#pubsubfactorycreate-transport-options-).
- `options.listenOptions`: Global options which will be applied to all subscriptions.
- `options.topicsNames`: Only subscribe to topics included in this whitelist.

## Other NestJS Google Cloud PubSub server

Other modules implementing Google Cloud PubSub with NestJS microservices:

- [crallen/nestjs-google-pubsub](https://github.com/crallen/nestjs-google-pubsub)
- [ecobee/nodejs-gcloud-pubsub-module](https://github.com/ecobee/nodejs-gcloud-pubsub-module)

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