Pipes

There is no difference between microservices pipes and the regular pipes. The only thing you should be aware of is that instead of throwing HttpException, you should use the RpcException.

info Hint The RpcException class is exposed from @nestjs/microservices package.

Binding pipes

Here is an example that makes use of a manually instantiated method-scoped pipe (class-scoped works too):

  1. @@filename()
  2. @UsePipes(new ValidationPipe())
  3. @MessagePattern({ cmd: 'sum' })
  4. accumulate(data: number[]): number {
  5. return (data || []).reduce((a, b) => a + b);
  6. }
  7. @@switch
  8. @UsePipes(new ValidationPipe())
  9. @MessagePattern({ cmd: 'sum' })
  10. accumulate(data) {
  11. return (data || []).reduce((a, b) => a + b);
  12. }