MQTT Transport interface - abstraction over MQTT client. Used by NodeMQTTOrchestrator for all MQTT operations.

interface MQTTTransport {
    connect(config: ESPMQTTConfig): Promise<void>;
    disconnect(): Promise<void>;
    isConnected(): Promise<boolean>;
    once(
        topic: string,
        handler: (topic: string, payload: Buffer) => void,
    ): Promise<void>;
    onConnectionStatusChange(
        callback: (status: { connected: boolean }) => void,
    ): () => void;
    publish(
        topic: string,
        payload: string | Buffer<ArrayBufferLike>,
    ): Promise<void>;
    subscribe(
        topic: string,
        handler: (topic: string, payload: Buffer) => void,
    ): Promise<void>;
    unsubscribe(
        topic: string,
        handler?: (topic: string, payload: Buffer) => void,
    ): Promise<void>;
}

Implemented by

Methods

  • Parameters

    • topic: string
    • handler: (topic: string, payload: Buffer) => void

    Returns Promise<void>

    Optional helper for request-response patterns. Invokes the handler once and auto-unsubscribes. Not required by NodeMQTTOrchestrator.

  • Optional push notification when the transport connects or drops. Returns an unsubscribe function. Not required by NodeMQTTOrchestrator; adapters that omit it simply do not surface async status changes.

    Parameters

    • callback: (status: { connected: boolean }) => void

      Invoked with { connected } on status changes

    Returns () => void

  • Publish a message to a topic.

    Parameters

    • topic: string

      MQTT topic to publish to

    • payload: string | Buffer<ArrayBufferLike>

      Message payload to publish

    Returns Promise<void>

  • Subscribe to a topic with a message handler.

    Parameters

    • topic: string

      MQTT topic to subscribe to

    • handler: (topic: string, payload: Buffer) => void

      Callback invoked when a message is received on the topic

    Returns Promise<void>

    The handler function reference is used to manage subscriptions. The same handler must be passed to unsubscribe to remove it.

  • Unsubscribe from a topic.

    Parameters

    • topic: string

      MQTT topic to unsubscribe from

    • Optionalhandler: (topic: string, payload: Buffer) => void

      Optional handler to remove

    Returns Promise<void>

    If a handler was provided during subscription, the same function reference must be passed to successfully unsubscribe it.

    Passing a different function (even if identical in implementation) will not remove the original handler.

    If handler is omitted, all handlers for the topic may be removed, depending on the implementation.