How to use the @nestjs/microservices.GrpcStreamMethod 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
}

  // grpc streaming methods

  @GrpcStreamMethod('HeroService')
  async getHeroByIdStream(messages: Observable): Promise {
    return new Promise((resolve, reject) => {
      messages.subscribe(msg => {
        resolve(this.items.find(({ id }) => id === msg.id));
      }, err => {
        reject(err);
      });
    });
  }

  @GrpcStreamMethod('HeroService')
  async listHeroesByNameStream(messages: Observable): Promise {
    return new Promise((resolve, reject) => {
      messages.subscribe(msg => {
        resolve({ heroes: this.items.filter(({ name }) => name.startsWith(msg.name)) });
      }, err => {
        reject(err);
      });
    });
  }

}
github kmturley / angular-nest-grpc / backend / src / hero / hero.controller.ts View on Github external
// grpc methods

  @GrpcMethod('HeroService')
  getHeroById(data: HeroById, metadata: any): Hero {
    return this.items.find(({ id }) => id === data.id);
  }

  @GrpcMethod('HeroService')
  listHeroesByName(data: HeroByName, metadata: any): object {
    return { heroes: this.items.filter(({ name }) => name.startsWith(data.name)) };
  }

  // grpc streaming methods

  @GrpcStreamMethod('HeroService')
  async getHeroByIdStream(messages: Observable): Promise {
    return new Promise((resolve, reject) => {
      messages.subscribe(msg => {
        resolve(this.items.find(({ id }) => id === msg.id));
      }, err => {
        reject(err);
      });
    });
  }

  @GrpcStreamMethod('HeroService')
  async listHeroesByNameStream(messages: Observable): Promise {
    return new Promise((resolve, reject) => {
      messages.subscribe(msg => {
        resolve({ heroes: this.items.filter(({ name }) => name.startsWith(msg.name)) });
      }, err => {
github nestjs / nest / integration / microservices / src / grpc-advanced / advanced.grpc.controller.ts View on Github external
return of({
      id: 1,
      itemTypes: [1],
      shipmentType: {
        from: 'test',
        to: 'test1',
        carrier: 'test-carrier',
      },
    });
  }

  /**
   * GRPC stub implementation for sync stream method
   * @param messages
   */
  @GrpcStreamMethod('orders.OrderService')
  async sync(messages: Observable): Promise {
    const s = new Subject();
    const o = s.asObservable();
    messages.subscribe(msg => {
      s.next({
        id: 1,
        itemTypes: [1],
        shipmentType: {
          from: 'test',
          to: 'test1',
          carrier: 'test-carrier',
        },
      });
    });
    return o;
  }