Interceptors

There is no difference between regular interceptors and the microservices interceptors. Here is an example that makes use of a manually instantiated method-scoped interceptor (class-scoped works too):

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