Class MqttJsonPublisher<T>

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.central.support.BaseMqttConnectionObserver
net.solarnetwork.central.support.MqttJsonPublisher<T>
All Implemented Interfaces:
Function<T,Future<?>>, net.solarnetwork.common.mqtt.MqttConnectionObserver, net.solarnetwork.service.Identifiable

public class MqttJsonPublisher<T> extends BaseMqttConnectionObserver implements Function<T,Future<?>>
Basic service to publish objects to SolarFlux.
  • Constructor Details

    • MqttJsonPublisher

      public MqttJsonPublisher(String name, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Function<T,String> topicFn, boolean retained, net.solarnetwork.common.mqtt.MqttQos publishQos)
      Constructor.
      Parameters:
      name - the display name to use
      objectMapper - the mapper for JSON
      topicFn - the function to generate the MQTT topic for a given object
      retained - true to publish each message as retained
      publishQos - the publish QoS
  • Method Details

    • apply

      public Future<?> apply(T item)
      Specified by:
      apply in interface Function<T,Future<?>>
    • publish

      protected Future<?> publish(T item, String topic)
      Publish an item to a given topic.
      Parameters:
      item - the item
      topic - the topic
      Returns:
      the publish future
    • publish

      protected Future<?> publish(T item, String topic, boolean retained, net.solarnetwork.common.mqtt.MqttQos qos)
      Publish an item to a given topic.
      Parameters:
      item - the item
      topic - the topic
      retained - true if the message should have the retained flag set
      qos - the publish QoS to use
      Returns:
      the publish future
      Since:
      1.1