How to use the @nestjs/microservices.Client function in @nestjs/microservices

To help you get started, weโ€™ve selected a few @nestjs/microservices examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kmturley / angular-nest-grpc / backend / src / hero / hero.controller.ts View on Github external
ClientGrpc,
} from '@nestjs/microservices';
import { Observable, Subject } from 'rxjs';
import { grpcClientOptions } from '../grpc-client.options';
import { HeroById } from './interfaces/hero-by-id.interface';
import { HeroByName } from './interfaces/hero-by-name.interface';
import { Hero, HeroList } from './interfaces/hero.interface';

interface HeroService {
  getHeroById(data: { id: number }): Observable;
  listHeroesByName(data: { name: string }): Observable;
}

@Controller()
export class HeroController implements OnModuleInit {
  @Client(grpcClientOptions) private readonly client: ClientGrpc;
  private heroService: HeroService;
  private items = [
    { id: 1, name: 'John' },
    { id: 2, name: 'Doe' },
    { id: 3, name: 'Billy' },
    { id: 4, name: 'Joey' },
  ];

  onModuleInit() {
    this.heroService = this.client.getService('HeroService');
  }

  // http methods

  @Get()
  call(): Observable {
github new-eden-social / new-eden-social / src / services / corporation / grpc / corporation.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Client, ClientGrpc } from '@nestjs/microservices';
import { ICorporationGrpcService } from './corporation.grpc.interface';
import { CorporationGrpcClientOptions } from './corporation.grpc.client.options';

@Injectable()
export class CorporationGrpcClient implements OnModuleInit {

  @Client(CorporationGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: ICorporationGrpcService;

  onModuleInit() {
    this.service = this.client.getService('CorporationService');
  }
}
github new-eden-social / new-eden-social / src / services / websocket / redis / websocket.redis.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { WebsocketRedisClientOptions } from './websocket.redis.client.options';
import { Client, ClientRedis } from '@nestjs/microservices';
import { WS_REDIS_EVENTS } from './websocket.redis.events';
import { Observable } from 'rxjs';
import { DWsRedisLatestWall, DWsRedisHashtagWall, DWsRedisCharacterWall, DWsRedisCorporationWall, DWsRedisAllianceWall, DWsRedisPostComments, DWsRedisCharacter } from './websocket.redis.dto';

@Injectable()
export class WebsocketRedisClient implements OnModuleInit {

  @Client(WebsocketRedisClientOptions)
  private readonly client: ClientRedis;

  async onModuleInit() {
    await this.client.connect();
  }

  public emitLatestWallEvent(data: T): Observable> {
    return this.client.emit>(
      WS_REDIS_EVENTS.LATEST_WALL,
      new DWsRedisLatestWall(data)
    );
  }

  public emitHashtagWallEvent(hashtag: string, data: T): Observable> {
    return this.client.emit>(
      WS_REDIS_EVENTS.HASHTAG_WALL,
github new-eden-social / new-eden-social / src / services / search / grpc / search.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Client, ClientGrpc } from '@nestjs/microservices';
import { ISearchGrpcService } from '@new-eden-social/services-search/grpc/search.grpc.interface';
import { SearchGrpcClientOptions } from '@new-eden-social/services-search/grpc/search.grpc.client.options';

@Injectable()
export class SearchGrpcClient implements OnModuleInit {

  @Client(SearchGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: ISearchGrpcService;

  onModuleInit() {
    this.service = this.client.getService('SearchService');
  }
}
github new-eden-social / new-eden-social / src / services / comment / grpc / comment.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Client, ClientGrpc } from '@nestjs/microservices';
import { ICommentGrpcService } from './comment.grpc.interface';
import { CommentGrpcClientOptions } from './comment.grpc.client.options';

@Injectable()
export class CommentGrpcClient implements OnModuleInit {

  @Client(CommentGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: ICommentGrpcService;

  onModuleInit() {
    this.service = this.client.getService('CommentService');
  }
}
github new-eden-social / new-eden-social / src / services / authenticate / grpc / authenticate.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Client, ClientGrpc } from '@nestjs/microservices';
import { IAuthenticateGrpcService } from '@new-eden-social/services-authenticate/grpc/authenticate.grpc.interface';
import { AuthenticateGrpcClientOptions } from '@new-eden-social/services-authenticate/grpc/authenticate.grpc.client.options';

@Injectable()
export class AuthenticateGrpcClient implements OnModuleInit {

  @Client(AuthenticateGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: IAuthenticateGrpcService;

  onModuleInit() {
    this.service = this.client.getService('AuthenticateService');
  }
}
github new-eden-social / new-eden-social / src / services / alliance / grpc / alliance.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { IAllianceGrpcService } from '@new-eden-social/services-alliance/grpc/alliance.grpc.interface';
import { AllianceGrpcClientOptions } from '@new-eden-social/services-alliance/grpc/alliance.grpc.client.options';
import { Client, ClientGrpc } from '@nestjs/microservices';

@Injectable()
export class AllianceGrpcClient implements OnModuleInit {

  @Client(AllianceGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: IAllianceGrpcService;

  onModuleInit() {
    this.service = this.client.getService('AllianceService');
  }
}
github new-eden-social / new-eden-social / src / services / universe / grpc / universe.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Client, ClientGrpc } from '@nestjs/microservices';
import { UniverseGrpcClientOptions } from '@new-eden-social/services-universe/grpc/universe.grpc.client.options';
import { IUniverseGrpcService } from '@new-eden-social/services-universe/grpc/universe.grpc.interface';

@Injectable()
export class UniverseGrpcClient implements OnModuleInit {

  @Client(UniverseGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: IUniverseGrpcService;

  onModuleInit() {
    this.service = this.client.getService('UniverseService');
  }
}
github new-eden-social / new-eden-social / src / services / hashtag / grpc / hashtag.grpc.client.ts View on Github external
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Client, ClientGrpc } from '@nestjs/microservices';
import { HashtagGrpcClientOptions } from '@new-eden-social/services-hashtag/grpc/hashtag.grpc.client.options';
import { IHashtagGrpcService } from '@new-eden-social/services-hashtag/grpc/hashtag.grpc.interface';

@Injectable()
export class HashtagGrpcClient implements OnModuleInit {

  @Client(HashtagGrpcClientOptions)
  private readonly client: ClientGrpc;
  public service: IHashtagGrpcService;

  onModuleInit() {
    this.service = this.client.getService('HashtagService');
  }
}
github notadd / nt-module-cms / src / grpc.client-factory.ts View on Github external
import { Injectable } from '@nestjs/common';
import { Client, ClientGrpc, GrpcOptions, Transport } from '@nestjs/microservices';
import { join } from 'path';

@Injectable()
export class NotaddGrpcClientFactory {
    @Client(generateGrpcOptions('localhost:50051', 'nt_module_user', 'nt_module_user.proto'))
    public readonly userModuleClient: ClientGrpc;
}

export function generateGrpcOptions(url: string, packageName: string, protoFileName: string): GrpcOptions {
    return {
        transport: Transport.GRPC,
        options: {
            url,
            package: packageName,
            protoPath: join(__dirname, 'grpc/protobufs/' + protoFileName),
            loader: {
                arrays: true
            }
        }
    };
}