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:
import { Module } from '@nestjs/common';
import { GCPubSubClient } from '../../src';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
controllers: [AppController],
providers: [
AppService,
{
provide: 'PUBSUB_CLIENT',
useFactory: () => {
return new GCPubSubClient({});
},
},
],
})
export class AppModule {}
Service:
import { Inject, OnModuleInit } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
export class AppService implements OnModuleInit {
constructor(@Inject('PUBSUB_CLIENT') private readonly client: ClientProxy) {}
public async onModuleInit(): Promise<void> {
await this.client.connect();
}
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