NestJS Logo

파이프

일반 파이프와 마이크로서비스 파이프 사이에는 근본적인 차이가 없습니다. 유일한 차이점은 HttpException을 throw하는 대신 RpcException을 사용해야 한다는 것입니다.

@nestjs/microservices 패키지에서 RpcException 클래스가 노출됩니다.

파이프 바인딩#

다음 예제는 수동으로 인스턴스화된 메서드 스코프 파이프를 사용합니다. HTTP 기반 애플리케이션과 마찬가지로 컨트롤러 스코프 파이프(예: 컨트롤러 클래스 앞에 @UsePipes() 데코레이터를 붙이는 것)도 사용할 수 있습니다.

JS TS

@UsePipes(new ValidationPipe({ exceptionFactory: (errors) => new RpcException(errors) }))
@MessagePattern({ cmd: 'sum' })
accumulate(data: number[]): number {
  return (data || []).reduce((a, b) => a + b);
}

@UsePipes(new ValidationPipe({ exceptionFactory: (errors) => new RpcException(errors) }))
@MessagePattern({ cmd: 'sum' })
accumulate(data) {
  return (data || []).reduce((a, b) => a + b);
}

Support us

Nest is an MIT-licensed open source project. It can grow thanks to the support by these awesome people. If you'd like to join them, please read more here.

Principal Sponsors

Trilon LogoMojam Logo

Sponsors / Partners

Become a sponsor