ServerGrpc

  
class ServerGrpc extends Server {
  constructor(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
  transportId: Transport.GRPC
  protected url: string
  protected grpcClient: GrpcServer
  status: never
  listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void)
  start(callback?: () => void)
  bindEvents()
  getServiceNames(grpcPkg: any): {...}
  createService(grpcService: any, name: string)
  getMessageHandler(serviceName: string, methodName: string, streaming: GrpcMethodStreamingType, grpcMethod: { path?: string; }): MessageHandler
  createPattern(service: string, methodName: string, streaming: GrpcMethodStreamingType): string
  createServiceMethod(methodHandler: Function, protoNativeHandler: any, streamType: GrpcMethodStreamingType): Function
  createUnaryServiceMethod(methodHandler: Function): Function
  createStreamServiceMethod(methodHandler: Function): Function
  unwrap<T>(): T
  on<EventKey extends string | number | symbol = string | number | symbol, EventCallback = any>(event: EventKey, callback: EventCallback)
  createRequestStreamMethod(methodHandler: Function, isResponseStream: boolean)
  createStreamCallMethod(methodHandler: Function, isResponseStream: boolean)
  close(): Promise<void>
  deserialize(obj: any): any
  addHandler(pattern: unknown, callback: MessageHandler<any, any, any>, isEventHandler: boolean = false)
  createClient()
  lookupPackage(root: any, packageName: string)
  loadProto(): any

  // inherited from nest/packages/microservices/Server
  transportId?: Transport | symbol
  protected messageHandlers: Map<string, MessageHandler>
  protected logger: LoggerService
  protected serializer: ConsumerSerializer
  protected deserializer: ConsumerDeserializer
  protected _status$: ReplaySubject<Status>
  status: Observable<Status>
  abstract on<EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback): any
  abstract unwrap<T>(): T
  abstract listen(callback: (...optionalParams: unknown[]) => any): any
  abstract close(): any
  addHandler(pattern: any, callback: MessageHandler<any, any, any>, isEventHandler: boolean = false, extras: Record<string, any> = {})
  getHandlers(): Map<string, MessageHandler>
  getHandlerByPattern(pattern: string): MessageHandler | null
  send(stream$: Observable<any>, respond: (data: WritePacket<any>) => void | Promise<unknown>): Subscription
  handleEvent(pattern: string, packet: ReadPacket<any>, context: BaseRpcContext<unknown[]>): Promise<any>
  transformToObservable(resultOrDeferred: any)
  getOptionsProp<Options extends MicroserviceOptions['options'], Attribute extends keyof Options, DefaultValue extends Options[Attribute] = Options[Attribute]>(obj: Options, prop: Attribute, defaultValue: DefaultValue = undefined as DefaultValue)
  protected handleError(error: string)
  protected loadPackage<T = any>(name: string, ctx: string, loader?: Function): T
  protected initializeSerializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
  protected initializeDeserializer(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)
  protected getRouteFromPattern(pattern: string): string
  protected normalizePattern(pattern: MsPattern): string
}

Constructor


constructor(options: { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...)

Parameters

Option Type Description
options { url?: string; maxSendMessageLength?: number; maxReceiveMessageLength?: number; maxMetadataSize?: number; keepalive?: { keepaliveTimeMs?: number; keepaliveTimeoutMs?: number; keepalivePermitWithoutCalls?: number; http2MaxPingsWithoutData?: number; http2MinTimeBetweenPingsMs?: number; http2MinPingIntervalWithoutData...

Properties

Property Description
transportId: Transport.GRPC Read-only.
protected url: string Read-only.
protected grpcClient: GrpcServer
status: never Read-only.

Methods

listen()


listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void)

Parameters

Option Type Description
callback (err?: unknown, ...optionalParams: unknown[]) => void

start()


start(callback?: () => void)

Parameters

Option Type Description
callback () => void

Optional. Default is undefined.

bindEvents()


bindEvents()

Parameters

There are no parameters.

getServiceNames()

Will return all of the services along with their fully namespaced names as an array of objects. This method initiates recursive scan of grpcPkg object


getServiceNames(grpcPkg: any): {
    name: string;
    service: any;
}[]

Parameters

Option Type Description
grpcPkg any

Returns

{ name: string; service: any; }[]

createService()

Will create service mapping from gRPC generated Object to handlers defined with @GrpcMethod or @GrpcStreamMethod annotations


createService(grpcService: any, name: string)

Parameters

Option Type Description
grpcService any
name string

getMessageHandler()


getMessageHandler(serviceName: string, methodName: string, streaming: GrpcMethodStreamingType, grpcMethod: { path?: string; }): MessageHandler

Parameters

Option Type Description
serviceName string
methodName string
streaming GrpcMethodStreamingType
grpcMethod { path?: string; }

Returns

MessageHandler

createPattern()

Will create a string of a JSON serialized format


createPattern(service: string, methodName: string, streaming: GrpcMethodStreamingType): string

Parameters

Option Type Description
service string

name of the service which should be a match to gRPC service definition name

methodName string

name of the method which is coming after rpc keyword

streaming GrpcMethodStreamingType

GrpcMethodStreamingType parameter which should correspond to stream keyword in gRPC service request part

Returns

string

createServiceMethod()

Will return async function which will handle gRPC call with Rx streams or as a direct call passthrough


createServiceMethod(methodHandler: Function, protoNativeHandler: any, streamType: GrpcMethodStreamingType): Function

Parameters

Option Type Description
methodHandler Function
protoNativeHandler any
streamType GrpcMethodStreamingType

Returns

Function

createUnaryServiceMethod()


createUnaryServiceMethod(methodHandler: Function): Function

Parameters

Option Type Description
methodHandler Function

Returns

Function

createStreamServiceMethod()


createStreamServiceMethod(methodHandler: Function): Function

Parameters

Option Type Description
methodHandler Function

Returns

Function

unwrap()


unwrap<T>(): T

Parameters

There are no parameters.

Returns

T

on()


on<EventKey extends string | number | symbol = string | number | symbol, EventCallback = any>(event: EventKey, callback: EventCallback)

Parameters

Option Type Description
event EventKey
callback EventCallback

createRequestStreamMethod()


createRequestStreamMethod(methodHandler: Function, isResponseStream: boolean)

Parameters

Option Type Description
methodHandler Function
isResponseStream boolean

createStreamCallMethod()


createStreamCallMethod(methodHandler: Function, isResponseStream: boolean)

Parameters

Option Type Description
methodHandler Function
isResponseStream boolean

close()


close(): Promise<void>

Parameters

There are no parameters.

Returns

Promise<void>

deserialize()


deserialize(obj: any): any

Parameters

Option Type Description
obj any

Returns

any

addHandler()


addHandler(pattern: unknown, callback: MessageHandler<any, any, any>, isEventHandler: boolean = false)

Parameters

Option Type Description
pattern unknown
callback MessageHandler
isEventHandler boolean

Optional. Default is false.

createClient()


createClient()

Parameters

There are no parameters.

lookupPackage()


lookupPackage(root: any, packageName: string)

Parameters

Option Type Description
root any
packageName string

loadProto()


loadProto(): any

Parameters

There are no parameters.

Returns

any