Class ProvisioningMqttPublisher

java.lang.Object
energy.eddie.aiida.provisioning.ProvisioningMqttPublisher
All Implemented Interfaces:
AutoCloseable, org.eclipse.paho.mqttv5.client.MqttCallback

public class ProvisioningMqttPublisher extends Object implements org.eclipse.paho.mqttv5.client.MqttCallback, AutoCloseable
  • Constructor Details

    • ProvisioningMqttPublisher

      public ProvisioningMqttPublisher(MqttConnection mqttConnection, String topic)
      Creates a publisher and starts an asynchronous connection to the configured MQTT broker.
      Parameters:
      mqttConnection - MQTT connection and credentials used by the publisher.
      topic - Topic to which inbound records are published.
    • ProvisioningMqttPublisher

      public ProvisioningMqttPublisher(MqttConnection mqttConnection, String topic, String connectionUsername, String connectionPassword)
      Creates a publisher with connection credentials that are independent of the persisted provisioning user. Server mode uses this overload so AIIDA connects with its stable broker identity while the generated per-permission user remains dedicated to the provisioning client.
      Parameters:
      mqttConnection - MQTT connection and persisted username.
      topic - Topic to which inbound records are published.
      connectionUsername - Username used to authenticate this publisher.
      connectionPassword - Plaintext password used to authenticate this publisher.
  • Method Details

    • publish

      public void publish(InboundRecord inboundRecord)
      Publishes the payload of an inbound record when the MQTT client is connected. If the client is disconnected or publishing fails, the record is not sent and the method returns without propagating an MQTT exception.
      Parameters:
      inboundRecord - Record whose payload should be published.
    • close

      public void close()
      Disconnects and closes the MQTT client. MQTT errors encountered during shutdown are logged and not propagated.
      Specified by:
      close in interface AutoCloseable
    • isConnected

      public boolean isConnected()
      Indicates whether the publisher currently has an established MQTT connection.
      Returns:
      true when an MQTT client exists and is connected; otherwise false.
    • disconnected

      public void disconnected(org.eclipse.paho.mqttv5.client.MqttDisconnectResponse disconnectResponse)
      Specified by:
      disconnected in interface org.eclipse.paho.mqttv5.client.MqttCallback
    • mqttErrorOccurred

      public void mqttErrorOccurred(org.eclipse.paho.mqttv5.common.MqttException exception)
      Specified by:
      mqttErrorOccurred in interface org.eclipse.paho.mqttv5.client.MqttCallback
    • messageArrived

      public void messageArrived(String topic, org.eclipse.paho.mqttv5.common.MqttMessage message) throws Exception
      Specified by:
      messageArrived in interface org.eclipse.paho.mqttv5.client.MqttCallback
      Throws:
      Exception
    • deliveryComplete

      public void deliveryComplete(org.eclipse.paho.mqttv5.client.IMqttToken token)
      Specified by:
      deliveryComplete in interface org.eclipse.paho.mqttv5.client.MqttCallback
    • connectComplete

      public void connectComplete(boolean reconnect, String serverURI)
      Specified by:
      connectComplete in interface org.eclipse.paho.mqttv5.client.MqttCallback
    • authPacketArrived

      public void authPacketArrived(int reasonCode, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties)
      Specified by:
      authPacketArrived in interface org.eclipse.paho.mqttv5.client.MqttCallback