Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MqttClient

An MQTT client

Hierarchy

  • MqttClient

Index

Methods

clientId

  • clientId(): string
  • Returns string

closeHandler

  • closeHandler(closeHandler: ((res: void) => void) | Handler<void>): MqttClient
  • Set a handler that will be called when the connection with server is closed

    Parameters

    • closeHandler: ((res: void) => void) | Handler<void>

    Returns MqttClient

connect

  • Connects to an MQTT server calling connectHandler after connection

    Parameters

    • port: number
    • host: string

    Returns PromiseLike<MqttConnAckMessage>

  • Connects to an MQTT server calling connectHandler after connection

    Parameters

    Returns MqttClient

  • Connects to an MQTT server calling connectHandler after connection

    Parameters

    • port: number
    • host: string
    • serverName: string

    Returns PromiseLike<MqttConnAckMessage>

  • Connects to an MQTT server calling connectHandler after connection

    Parameters

    Returns MqttClient

disconnect

  • disconnect(): PromiseLike<void>
  • disconnect(disconnectHandler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): MqttClient
  • Disconnects from the MQTT server calling disconnectHandler after disconnection

    Returns PromiseLike<void>

  • Disconnects from the MQTT server calling disconnectHandler after disconnection

    Parameters

    • disconnectHandler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns MqttClient

exceptionHandler

  • exceptionHandler(handler: ((res: Throwable) => void) | Handler<Throwable>): MqttClient
  • Set an exception handler for the client, that will be called when an error happens in internal netty structures.

    io.netty.handler.codec.DecoderException can be one of the cause

    Parameters

    • handler: ((res: Throwable) => void) | Handler<Throwable>

    Returns MqttClient

isConnected

  • isConnected(): boolean
  • Returns boolean

ping

  • This method is needed by the client in order to avoid server closes the connection due to the keep alive timeout if client has no messages to send

    Returns MqttClient

pingResponseHandler

  • pingResponseHandler(pingResponseHandler: ((res: void) => void) | Handler<void>): MqttClient
  • Sets handler which will be called after PINGRESP packet receiving

    Parameters

    • pingResponseHandler: ((res: void) => void) | Handler<void>

    Returns MqttClient

publish

  • publish(topic: string, payload: Buffer, qosLevel: any, isDup: boolean, isRetain: boolean): PromiseLike<number>
  • publish(topic: string, payload: Buffer, qosLevel: any, isDup: boolean, isRetain: boolean, publishSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>): MqttClient
  • Sends the PUBLISH message to the remote MQTT server

    Parameters

    • topic: string
    • payload: Buffer
    • qosLevel: any
    • isDup: boolean
    • isRetain: boolean

    Returns PromiseLike<number>

  • Sends the PUBLISH message to the remote MQTT server

    Parameters

    • topic: string
    • payload: Buffer
    • qosLevel: any
    • isDup: boolean
    • isRetain: boolean
    • publishSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>

    Returns MqttClient

publishCompletionExpirationHandler

  • publishCompletionExpirationHandler(publishCompletionExpirationHandler: ((res: number) => void) | Handler<number>): MqttClient
  • Sets a handler which will be called when the client does not receive a PUBACK or PUBREC/PUBCOMP for a message published using QoS 1 or 2 respectively.

    The time to wait for an acknowledgement message can be configured using MqttClientOptions. If the client receives a PUBACK/PUBREC/PUBCOMP for a message after its completion has expired, the handler registered using {@link MqttClient#publishCompletionUnknownPacketIdHandler} will be invoked.

    Note that this behavior is outside the scope of the MQTT 3.1.1 specification. The client's default behavior is therefore to wait forever for the server's corresponding acknowledgement.

    Parameters

    • publishCompletionExpirationHandler: ((res: number) => void) | Handler<number>

    Returns MqttClient

publishCompletionHandler

  • publishCompletionHandler(publishCompletionHandler: ((res: number) => void) | Handler<number>): MqttClient
  • Sets a handler which will be called each time the publishing of a message has been completed.

    For a message that has been published using

    • QoS 0 this means that the client has successfully sent the corresponding PUBLISH packet,
    • QoS 1 this means that a corresponding PUBACK has been received from the server,
    • QoS 2 this means that a corresponding PUBCOMP has been received from the server.

    Parameters

    • publishCompletionHandler: ((res: number) => void) | Handler<number>

    Returns MqttClient

publishCompletionUnknownPacketIdHandler

  • publishCompletionUnknownPacketIdHandler(publishCompletionPhantomHandler: ((res: number) => void) | Handler<number>): MqttClient
  • Sets a handler which will be called when the client receives a PUBACK/PUBREC/PUBCOMP with an unknown packet ID.

    Parameters

    • publishCompletionPhantomHandler: ((res: number) => void) | Handler<number>

    Returns MqttClient

publishHandler

  • Sets handler which will be called each time server publish something to client

    Parameters

    Returns MqttClient

subscribe

  • subscribe(topic: string, qos: number): PromiseLike<number>
  • subscribe(topic: string, qos: number, subscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>): MqttClient
  • subscribe(topics: {}): PromiseLike<number>
  • subscribe(topics: {}, subscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>): MqttClient
  • Subscribes to the topic with a specified QoS level

    Parameters

    • topic: string
    • qos: number

    Returns PromiseLike<number>

  • Subscribes to the topic with a specified QoS level

    Parameters

    • topic: string
    • qos: number
    • subscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>

    Returns MqttClient

  • Subscribes to the topic and adds a handler which will be called after the request is sent

    Parameters

    • topics: {}
      • [key: string]: number

    Returns PromiseLike<number>

  • Subscribes to the topic and adds a handler which will be called after the request is sent

    Parameters

    • topics: {}
      • [key: string]: number
    • subscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>

    Returns MqttClient

subscribeCompletionHandler

  • Sets handler which will be called after SUBACK packet receiving

    Parameters

    Returns MqttClient

unsubscribe

  • unsubscribe(topics: string): PromiseLike<number>
  • unsubscribe(topics: string, unsubscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>): MqttClient
  • unsubscribe(topic: string): PromiseLike<number>
  • unsubscribe(topic: string, unsubscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>): MqttClient
  • Unsubscribe from receiving messages on given topics

    Parameters

    • topics: string

    Returns PromiseLike<number>

  • Unsubscribe from receiving messages on given topics

    Parameters

    • topics: string
    • unsubscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>

    Returns MqttClient

  • Unsubscribe from receiving messages on given topic

    Parameters

    • topic: string

    Returns PromiseLike<number>

  • Unsubscribe from receiving messages on given topic

    Parameters

    • topic: string
    • unsubscribeSentHandler: ((res: AsyncResult<number>) => void) | Handler<AsyncResult<number>>

    Returns MqttClient

unsubscribeCompletionHandler

  • unsubscribeCompletionHandler(unsubscribeCompletionHandler: ((res: number) => void) | Handler<number>): MqttClient
  • Sets handler which will be called after UNSUBACK packet receiving

    Parameters

    • unsubscribeCompletionHandler: ((res: number) => void) | Handler<number>

    Returns MqttClient

Static create

  • Return an MQTT client instance

    Parameters

    Returns MqttClient

  • Return an MQTT client instance using the default options

    Parameters

    • vertx: Vertx

    Returns MqttClient

Generated using TypeDoc