Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algoan/nestjs-google-pubsub-client

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algoan/nestjs-google-pubsub-client

A NestJS ClientProxy for Google Cloud PubSub

  • 0.4.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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

Keywords

FAQs

Package last updated on 16 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc