ClientNats

  
class ClientNats extends ClientProxy {
  constructor(options: { [key: string]: any; headers?: Record<string, string>; authenticator?: any; debug?: boolean; ignoreClusterUpdates?: boolean; inboxPrefix?: string; encoding?: string; name?: string; user?: string; ... 30 more ...; gracePeriod?: number; })
  protected logger: Logger
  protected natsClient: Client | null
  protected connectionPromise: Promise<Client> | null
  protected statusEventEmitter: EventEmitter<{...}
  protected options: Required<NatsOptions>['options']
  close()
  connect(): Promise<any>
  createClient(): Promise<Client>
  handleStatusUpdates(client: Client)
  on<EventKey extends keyof NatsEvents = keyof NatsEvents, EventCallback extends NatsEvents[EventKey] = NatsEvents[EventKey]>(event: EventKey, callback: EventCallback)
  unwrap<T>(): T
  createSubscriptionHandler(packet: ReadPacket<any> & PacketId, callback: (packet: WritePacket<any>) => any)
  protected publish(partialPacket: ReadPacket<any>, callback: (packet: WritePacket<any>) => any): () => void
  protected dispatchEvent(packet: ReadPacket<any>): Promise<any>
  protected initializeSerializer(options: { [key: string]: any; headers?: Record<string, string>; authenticator?: any; debug?: boolean; ignoreClusterUpdates?: boolean; inboxPrefix?: string; encoding?: string; name?: string; user?: string; ... 30 more ...; gracePeriod?: number; })
  protected initializeDeserializer(options: { [key: string]: any; headers?: Record<string, string>; authenticator?: any; debug?: boolean; ignoreClusterUpdates?: boolean; inboxPrefix?: string; encoding?: string; name?: string; user?: string; ... 30 more ...; gracePeriod?: number; })
  protected mergeHeaders<THeaders = any>(requestHeaders?: THeaders)

  // inherited from nest/packages/microservices/ClientProxy
  protected routingMap: Map<string, Function>
  protected serializer: ProducerSerializer
  protected deserializer: ProducerDeserializer
  protected _status$: ReplaySubject<Status>
  status: Observable<Status>
  abstract connect(): Promise<any>
  abstract close(): any
  on<EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback)
  abstract unwrap<T>(): T
  send<TResult = any, TInput = any>(pattern: any, data: TInput): Observable<TResult>
  emit<TResult = any, TInput = any>(pattern: any, data: TInput): Observable<TResult>
  protected abstract publish(packet: ReadPacket<any>, callback: (packet: WritePacket<any>) => void): () => void
  protected abstract dispatchEvent<T = any>(packet: ReadPacket<any>): Promise<T>
  protected createObserver<T>(observer: Observer<T>): (packet: WritePacket) => void
  protected serializeError(err: any): any
  protected serializeResponse(response: any): any
  protected assignPacketId(packet: ReadPacket<any>): ReadPacket & PacketId
  protected connect$(instance: any, errorEvent: string = 'error', connectEvent: string = 'connect'): Observable<any>
  protected getOptionsProp<Options extends ClientOptions['options'], Attribute extends keyof Options, DefaultValue extends Options[Attribute] = Options[Attribute]>(obj: Options, prop: Attribute, defaultValue: DefaultValue = undefined as DefaultValue)
  protected normalizePattern(pattern: MsPattern): string
  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...)
}

Constructor


constructor(options: { [key: string]: any; headers?: Record<string, string>; authenticator?: any; debug?: boolean; ignoreClusterUpdates?: boolean; inboxPrefix?: string; encoding?: string; name?: string; user?: string; ... 30 more ...; gracePeriod?: number; })

Parameters

Option Type Description
options object

Properties

Property Description
protected logger: Logger Read-only.
protected natsClient: Client | null
protected connectionPromise: Promise<Client> | null
protected statusEventEmitter: EventEmitter<{ [key in keyof NatsEvents]: Parameters<NatsEvents[key]>; }>
protected options: Required<NatsOptions>['options'] Read-only. Declared in constructor.

Methods

close()


close()

Parameters

There are no parameters.

connect()


connect(): Promise<any>

Parameters

There are no parameters.

Returns

Promise<any>

createClient()


createClient(): Promise<Client>

Parameters

There are no parameters.

Returns

Promise<Client>

handleStatusUpdates()


handleStatusUpdates(client: Client)

Parameters

Option Type Description
client Client

on()


on<EventKey extends keyof NatsEvents = keyof NatsEvents, EventCallback extends NatsEvents[EventKey] = NatsEvents[EventKey]>(event: EventKey, callback: EventCallback)

Parameters

Option Type Description
event EventKey
callback EventCallback

unwrap()


unwrap<T>(): T

Parameters

There are no parameters.

Returns

T

createSubscriptionHandler()


createSubscriptionHandler(packet: ReadPacket<any> & PacketId, callback: (packet: WritePacket<any>) => any)

Parameters

Option Type Description
packet ReadPacket & PacketId
callback (packet: WritePacket) => any

publish()


protected publish(partialPacket: ReadPacket<any>, callback: (packet: WritePacket<any>) => any): () => void

Parameters

Option Type Description
partialPacket ReadPacket
callback (packet: WritePacket) => any

Returns

() => void

dispatchEvent()


protected dispatchEvent(packet: ReadPacket<any>): Promise<any>

Parameters

Option Type Description
packet ReadPacket

Returns

Promise<any>

initializeSerializer()


protected initializeSerializer(options: { [key: string]: any; headers?: Record<string, string>; authenticator?: any; debug?: boolean; ignoreClusterUpdates?: boolean; inboxPrefix?: string; encoding?: string; name?: string; user?: string; ... 30 more ...; gracePeriod?: number; })

Parameters

Option Type Description
options object

initializeDeserializer()


protected initializeDeserializer(options: { [key: string]: any; headers?: Record<string, string>; authenticator?: any; debug?: boolean; ignoreClusterUpdates?: boolean; inboxPrefix?: string; encoding?: string; name?: string; user?: string; ... 30 more ...; gracePeriod?: number; })

Parameters

Option Type Description
options object

mergeHeaders()


protected mergeHeaders<THeaders = any>(requestHeaders?: THeaders)

Parameters

Option Type Description
requestHeaders THeaders

Optional. Default is undefined.