Interceptors

There is no difference between regular interceptors and microservices interceptors. The following example uses a manually instantiated method-scoped interceptor. Just as with HTTP based applications, you can also use controller-scoped interceptors (i.e., prefix the controller class with a @UseInterceptors() decorator).

  1. @UseInterceptors(new TransformInterceptor())
  2. @MessagePattern({ cmd: 'sum' })
  3. accumulate(data: number[]): number {
  4. return (data || []).reduce((a, b) => a + b);
  5. }
  1. @UseInterceptors(new TransformInterceptor())
  2. @MessagePattern({ cmd: 'sum' })
  3. accumulate(data) {
  4. return (data || []).reduce((a, b) => a + b);
  5. }