0.4.11 • Published 5 months ago

@algoan/nestjs-google-pubsub-client v0.4.11

Weekly downloads
363
License
ISC
Repository
github
Last release
5 months ago

google-pubsub-client

The client extends the ClientProxy class and have to override the emit method using @algoan/pubsub.

⚠️ This Client only overrides the abstract dispatchEvent method. Therefore, only the client#emit method can be called.

Installation

npm install --save @algoan/pubsub @algoan/nestjs-google-pubsub-client

Usage

To instantiate the GCPubSubClient:

Module:

// app.module.ts
import { Module } from '@nestjs/common';

import { GCPubSubClient } from '../../src';
import { AppController } from './app.controller';
import { AppService } from './app.service';

/**
 * App module
 */
@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'PUBSUB_CLIENT',
      useFactory: () => {
        // Use a factory to add you custom options
        return new GCPubSubClient({});
      },
    },
  ],
})
export class AppModule {}

Service:

import { Inject, OnModuleInit } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';

/**
 * Fake app service
 */
export class AppService implements OnModuleInit {
  constructor(@Inject('PUBSUB_CLIENT') private readonly client: ClientProxy) {}

  /**
   * Connect the client proxy on module init
   * NOTE: this is optional with GooglePubSubClient. It is called anyway in the emit method
   * See https://github.com/nestjs/nest/blob/master/packages/microservices/client/client-proxy.ts#L67
   */
  public async onModuleInit(): Promise<void> {
    await this.client.connect();
  }
  /**
   * Emit a test event
   * @param data Payload sent
   */
  public emitTestEvent(data: { hello: string }): void {
    this.client.emit('test_event', data);
  }
}

new GCPubSubClient(options)

Initiate a new Google Cloud PubSub Client proxy.

  • options: Options related to the GC PubSub instance. More details on options here
0.4.11

5 months ago

0.4.10

6 months ago

0.4.9

11 months ago

0.4.8

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.4

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago