Class MqttStreamer

java.lang.Object
energy.eddie.aiida.streamers.AiidaStreamer
energy.eddie.aiida.streamers.mqtt.MqttStreamer
All Implemented Interfaces:
AutoCloseable, org.eclipse.paho.mqttv5.client.MqttCallback

public class MqttStreamer extends AiidaStreamer implements org.eclipse.paho.mqttv5.client.MqttCallback
  • Constructor Details

    • MqttStreamer

      public MqttStreamer(FailedToSendRepository failedToSendRepository, tools.jackson.databind.ObjectMapper mapper, Permission permission, reactor.core.publisher.Flux<AiidaRecord> recordFlux, SchemaFormatterRegistry schemaFormatterRegistry, MqttStreamingContext streamingContext, reactor.core.publisher.Sinks.Many<PermissionCommand> commandSink)
      Creates a new MqttStreamer and initialized the client callback.
      Parameters:
      failedToSendRepository - Repository where messages that could not be transmitted are stored.
      mapper - ObjectMapper used to transform the values to be sent into JSON strings.
      permission - Permission for which this streamer is created.
      recordFlux - Flux, where records that should be sent are published.
      schemaFormatterRegistry - Registry of all available schema formatters
      streamingContext - Holds the MqttAsyncClient used to send to MQTT broker and the necessary MQTT configuration values.
      commandSink - Sink, to which a PermissionCommand is published when the EP sends a control command.
  • Method Details

    • connect

      public void connect()
      Description copied from class: AiidaStreamer
      Open required connections to the streaming target (EP) in this method, not beforehand. Subscribe to the Fluxes in this method, to receive records and status messages that shall be sent. Start listening for termination requests from the EP.
      Specified by:
      connect in class AiidaStreamer
    • close

      public void close()
      Description copied from class: AiidaStreamer
      Unsubscribe from any Flux and free any used resources in this method. May flush all queued messages beforehand.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class AiidaStreamer
    • closeTerminally

      public void closeTerminally(AiidaConnectionStatusMessageDto statusMessage)
      Description copied from class: AiidaStreamer
      Sends a AiidaConnectionStatusMessageDto with the passed status before closing this streamer for good. May block until the passed statusMessage is transmitted.
      Specified by:
      closeTerminally in class AiidaStreamer
      See Also:
    • 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)
      Specified by:
      messageArrived in interface org.eclipse.paho.mqttv5.client.MqttCallback
    • 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
    • setTransmissionEnabled

      public void setTransmissionEnabled(boolean enabled)
      Description copied from class: AiidaStreamer
      Enables or disables data transmission for this streamer. While disabled, records are not published to the EP.
      Specified by:
      setTransmissionEnabled in class AiidaStreamer
    • updateRecordFlux

      public void updateRecordFlux(reactor.core.publisher.Flux<AiidaRecord> recordFlux)
      Description copied from class: AiidaStreamer
      Replaces the record flux this streamer is subscribed to and resubscribes. Used to apply a new transmission schedule, which re-aggregates the upstream records on a different cadence.
      Specified by:
      updateRecordFlux in class AiidaStreamer
    • 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