INestMicroservice

Interface describing Microservice Context.


interface INestMicroservice extends INestApplicationContext {
  listen(): Promise<any>
  useWebSocketAdapter(adapter: WebSocketAdapter<any, any, any>): this
  useGlobalFilters(...filters: ExceptionFilter<any>[]): this
  useGlobalPipes(...pipes: PipeTransform<any, any>[]): this
  useGlobalInterceptors(...interceptors: NestInterceptor<any, any>[]): this
  useGlobalGuards(...guards: CanActivate[]): this
  close(): Promise<void>

  // inherited from nest/packages/common/INestApplicationContext
  select<T>(module: Type<T> | DynamicModule): INestApplicationContext
  get<TInput = any, TResult = TInput>(typeOrToken: string | symbol | Function | Type<TInput>): TResult
  resolve<TInput = any, TResult = TInput>(typeOrToken: string | symbol | Function | Type<TInput>): Promise<TResult>
  registerRequestByContextId<T = any>(request: T, contextId: { id: number; }): void
  close(): Promise<void>
  useLogger(logger: false | LoggerService | LogLevel[]): void
  flushLogs(): void
  enableShutdownHooks(signals?: string[] | ShutdownSignal[]): this
  init(): Promise<this>
}

Methods

listen()

Starts the microservice.


listen(): Promise<any>

Parameters

There are no parameters.

Returns

Promise<any>

useWebSocketAdapter()

Register Ws Adapter which will be used inside Gateways. Use when you want to override default socket.io library.


useWebSocketAdapter(adapter: WebSocketAdapter<any, any, any>): this

Parameters

Option Type Description
adapter WebSocketAdapter

Returns

this

useGlobalFilters()

Registers exception filters as global filters (will be used within every message pattern handler)


useGlobalFilters(...filters: ExceptionFilter<any>[]): this

Parameters

Option Type Description
filters ExceptionFilter

Returns

this

useGlobalPipes()

Registers pipes as global pipes (will be used within every message pattern handler)


useGlobalPipes(...pipes: PipeTransform<any, any>[]): this

Parameters

Option Type Description
pipes PipeTransform

Returns

this

useGlobalInterceptors()

Registers interceptors as global interceptors (will be used within every message pattern handler)


useGlobalInterceptors(...interceptors: NestInterceptor<any, any>[]): this

Parameters

Option Type Description
interceptors NestInterceptor

Returns

this

useGlobalGuards()

Registers guards as global guards (will be used within every message pattern handler)


useGlobalGuards(...guards: CanActivate[]): this

Parameters

Option Type Description
guards CanActivate

Returns

this

close()

Terminates the application


close(): Promise<void>

Parameters

There are no parameters.

Returns

Promise<void>