ClientProxy

  
abstract class ClientProxy<EventsMap extends Record<never, Function> = Record<never, Function>, Status extends string = string> {
  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...)
}

Properties

Property Description
protected routingMap: Map<string, Function>
protected serializer: ProducerSerializer
protected deserializer: ProducerDeserializer
protected _status$: ReplaySubject<Status>
status: Observable<Status> Read-only.

Returns an observable that emits status changes.

Methods

connect()

Establishes the connection to the underlying server/broker.


abstract connect(): Promise<any>

Parameters

There are no parameters.

Returns

Promise<any>

close()

Closes the underlying connection to the server/broker.


abstract close(): any

Parameters

There are no parameters.

Returns

any

on()

Registers an event listener for the given event.


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

Parameters

Option Type Description
event EventKey

Event name

callback EventCallback

Callback to be executed when the event is emitted

unwrap()

Returns an instance of the underlying server/broker instance, or a group of servers if there are more than one.


abstract unwrap<T>(): T

Parameters

There are no parameters.

Returns

T

send()

Send a message to the server/broker. Used for message-driven communication style between microservices.


send<TResult = any, TInput = any>(pattern: any, data: TInput): Observable<TResult>

Parameters

Option Type Description
pattern any

Pattern to identify the message

data TInput

Data to be sent

Returns

Observable<TResult> Observable with the result

emit()

Emits an event to the server/broker. Used for event-driven communication style between microservices.


emit<TResult = any, TInput = any>(pattern: any, data: TInput): Observable<TResult>

Parameters

Option Type Description
pattern any

Pattern to identify the event

data TInput

Data to be sent

Returns

Observable<TResult> Observable that completes when the event is successfully emitted

publish()


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

Parameters

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

Returns

() => void

dispatchEvent()


protected abstract dispatchEvent<T = any>(packet: ReadPacket<any>): Promise<T>

Parameters

Option Type Description
packet ReadPacket

Returns

Promise<T>

createObserver()


protected createObserver<T>(observer: Observer<T>): (packet: WritePacket) => void

Parameters

Option Type Description
observer Observer

Returns

(packet: WritePacket) => void

serializeError()


protected serializeError(err: any): any

Parameters

Option Type Description
err any

Returns

any

serializeResponse()


protected serializeResponse(response: any): any

Parameters

Option Type Description
response any

Returns

any

assignPacketId()


protected assignPacketId(packet: ReadPacket<any>): ReadPacket & PacketId

Parameters

Option Type Description
packet ReadPacket

Returns

ReadPacket & PacketId

connect$()


protected connect$(instance: any, errorEvent: string = 'error', connectEvent: string = 'connect'): Observable<any>

Parameters

Option Type Description
instance any
errorEvent string

Optional. Default is 'error'.

connectEvent string

Optional. Default is 'connect'.

Returns

Observable<any>

getOptionsProp()


protected getOptionsProp<Options extends ClientOptions['options'], Attribute extends keyof Options>(obj: Options, prop: Attribute): Options[Attribute]

Parameters

Option Type Description
obj Options
prop Attribute

Returns

Options[Attribute]


protected getOptionsProp<Options extends ClientOptions['options'], Attribute extends keyof Options, DefaultValue extends Options[Attribute] = Options[Attribute]>(obj: Options, prop: Attribute, defaultValue: DefaultValue): Required<Options>[Attribute]

Parameters

Option Type Description
obj Options
prop Attribute
defaultValue DefaultValue

Returns

Required<Options>[Attribute]

normalizePattern()


protected normalizePattern(pattern: MsPattern): string

Parameters

Option Type Description
pattern MsPattern

Returns

string

initializeSerializer()


protected initializeSerializer(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...

initializeDeserializer()


protected initializeDeserializer(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...