ClientMqtt

  
class ClientMqtt extends ClientProxy {
  constructor(options: MqttClientOptions & { url?: string; serializer?: Serializer<any, any>; deserializer?: Deserializer<any, any>; subscribeOptions?: { qos: QoS; nl?: boolean; rap?: boolean; rh?: number; }; userProperties?: Record<...>; })
  protected logger: Logger
  protected subscriptionsCount: Map<string, number>
  protected url: string
  protected mqttClient: MqttClient
  protected connection: Promise<any>
  protected options: MqttOptions['options']
  getRequestPattern(pattern: string): string
  getResponsePattern(pattern: string): string
  close()
  connect(): Promise<any>
  mergeCloseEvent<T = any>(instance: MqttClient, source$: Observable<T>): Observable<T>
  createClient(): MqttClient
  handleError(client: MqttClient)
  createResponseCallback(): (channel: string, buffer: Buffer) => any
  protected publish(partialPacket: ReadPacket<any>, callback: (packet: WritePacket<any>) => any): () => void
  protected dispatchEvent(packet: ReadPacket<any>): Promise<any>
  protected unsubscribeFromChannel(channel: string)
  protected initializeSerializer(options: MqttClientOptions & { url?: string; serializer?: Serializer<any, any>; deserializer?: Deserializer<any, any>; subscribeOptions?: { qos: QoS; nl?: boolean; rap?: boolean; rh?: number; }; userProperties?: Record<...>; })
  protected mergePacketOptions(requestOptions?: MqttRecordOptions): MqttRecordOptions | undefined

  // inherited from nest/packages/microservices/ClientProxy
  protected routingMap: Map<string, Function>
  protected serializer: ProducerSerializer
  protected deserializer: ProducerDeserializer
  abstract connect(): Promise<any>
  abstract close(): any
  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_EVENT, connectEvent: string = CONNECT_EVENT): Observable<any>
  protected getOptionsProp<T extends ClientOptions['options'], K extends keyof T>(obj: T, prop: K, defaultValue: T[K] = undefined)
  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: MqttClientOptions & { url?: string; serializer?: Serializer<any, any>; deserializer?: Deserializer<any, any>; subscribeOptions?: { qos: QoS; nl?: boolean; rap?: boolean; rh?: number; }; userProperties?: Record<...>; })

Parameters

Option Type Description
options MqttClientOptions & { url?: string; serializer?: Serializer; deserializer?: Deserializer; subscribeOptions?: { qos: QoS; nl?: boolean; rap?: boolean; rh?: number; }; userProperties?: Record<...>; }

Properties

Property Description
protected logger: Logger Read-only.
protected subscriptionsCount: Map<string, number> Read-only.
protected url: string Read-only.
protected mqttClient: MqttClient
protected connection: Promise<any>
protected options: MqttOptions['options'] Read-only. Declared in constructor.

Methods

getRequestPattern()


getRequestPattern(pattern: string): string

Parameters

Option Type Description
pattern string

Returns

string

getResponsePattern()


getResponsePattern(pattern: string): string

Parameters

Option Type Description
pattern string

Returns

string

close()


close()

Parameters

There are no parameters.

connect()


connect(): Promise<any>

Parameters

There are no parameters.

Returns

Promise<any>

mergeCloseEvent()


mergeCloseEvent<T = any>(instance: MqttClient, source$: Observable<T>): Observable<T>

Parameters

Option Type Description
instance MqttClient
source$ Observable

Returns

Observable<T>

createClient()


createClient(): MqttClient

Parameters

There are no parameters.

Returns

MqttClient

handleError()


handleError(client: MqttClient)

Parameters

Option Type Description
client MqttClient

createResponseCallback()


createResponseCallback(): (channel: string, buffer: Buffer) => any

Parameters

There are no parameters.

Returns

(channel: string, buffer: Buffer) => 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>

unsubscribeFromChannel()


protected unsubscribeFromChannel(channel: string)

Parameters

Option Type Description
channel string

initializeSerializer()


protected initializeSerializer(options: MqttClientOptions & { url?: string; serializer?: Serializer<any, any>; deserializer?: Deserializer<any, any>; subscribeOptions?: { qos: QoS; nl?: boolean; rap?: boolean; rh?: number; }; userProperties?: Record<...>; })

Parameters

Option Type Description
options MqttClientOptions & { url?: string; serializer?: Serializer; deserializer?: Deserializer; subscribeOptions?: { qos: QoS; nl?: boolean; rap?: boolean; rh?: number; }; userProperties?: Record<...>; }

mergePacketOptions()


protected mergePacketOptions(requestOptions?: MqttRecordOptions): MqttRecordOptions | undefined

Parameters

Option Type Description
requestOptions MqttRecordOptions

Optional. Default is undefined.

Returns

MqttRecordOptions | undefined