11import { Logger } from '@nestjs/common/services/logger.service' ;
22import { loadPackage } from '@nestjs/common/utils/load-package.util' ;
3- import { isFunction } from '@nestjs/common/utils/shared.utils' ;
4- import { EMPTY as empty , Observable , Subscription , from as fromPromise , of } from 'rxjs' ;
3+ import { isFunction , isString } from '@nestjs/common/utils/shared.utils' ;
4+ import { EMPTY as empty , from as fromPromise , Observable , of , Subscription } from 'rxjs' ;
55import { catchError , finalize } from 'rxjs/operators' ;
66import { MessageHandlers } from '../interfaces/message-handlers.interface' ;
77import { MicroserviceOptions , WritePacket } from './../interfaces' ;
@@ -10,6 +10,14 @@ export abstract class Server {
1010 protected readonly messageHandlers : MessageHandlers = { } ;
1111 protected readonly logger = new Logger ( Server . name ) ;
1212
13+ public addHandler (
14+ pattern : any ,
15+ callback : ( data ) => Promise < Observable < any > > ,
16+ ) {
17+ const key = isString ( pattern ) ? pattern : JSON . stringify ( pattern ) ;
18+ this . messageHandlers [ key ] = callback ;
19+ }
20+
1321 public getHandlers ( ) : MessageHandlers {
1422 return this . messageHandlers ;
1523 }
@@ -20,13 +28,6 @@ export abstract class Server {
2028 return this . messageHandlers [ pattern ] ? this . messageHandlers [ pattern ] : null ;
2129 }
2230
23- public addHandler (
24- pattern : any ,
25- callback : ( data ) => Promise < Observable < any > > ,
26- ) {
27- this . messageHandlers [ JSON . stringify ( pattern ) ] = callback ;
28- }
29-
3031 public send (
3132 stream$ : Observable < any > ,
3233 respond : ( data : WritePacket ) => void ,
0 commit comments