Interface MqttTransport

All Known Implementing Classes:
PahoMqttTransport

public interface MqttTransport
Minimal MQTT transport abstraction used by MqttService. Keeps the bridge logic independent of any particular client library, so it can be exercised with an in-memory fake in tests and backed by PahoMqttTransport in production.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the connection and releases resources.
    void
    Establishes the broker connection.
    void
    publish(String topic, byte[] payload, int qos)
    Publishes a message.
    void
    subscribe(String topicFilter, int qos, BiConsumer<String,byte[]> handler)
    Subscribes to a topic filter, delivering matching messages to handler as (topic, payload).
  • Method Details

    • connect

      void connect() throws Exception
      Establishes the broker connection.
      Throws:
      Exception - if the connection cannot be established
    • publish

      void publish(String topic, byte[] payload, int qos) throws Exception
      Publishes a message.
      Parameters:
      topic - the topic to publish to
      payload - the message payload
      qos - the MQTT quality-of-service level (0/1/2)
      Throws:
      Exception - if publishing fails
    • subscribe

      void subscribe(String topicFilter, int qos, BiConsumer<String,byte[]> handler) throws Exception
      Subscribes to a topic filter, delivering matching messages to handler as (topic, payload).
      Parameters:
      topicFilter - the MQTT topic filter (may contain + / # wildcards)
      qos - the requested QoS
      handler - receives (topic, payload) for each matching message
      Throws:
      Exception - if subscribing fails
    • close

      void close()
      Closes the connection and releases resources.