Class AbstractMqttMessageDrivenChannelAdapter<T extends com.hivemq.client.mqtt.MqttClient>

Type Parameters:
T - MQTT Client type
All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, SmartInitializingSingleton, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, Phased, SmartLifecycle, ComponentSourceAware, ExpressionCapable, MessageProducer, IntegrationPattern, ClientManager.ConnectCallback, NamedComponent, IntegrationInboundManagement, IntegrationManagement, ManageableLifecycle, ManageableSmartLifecycle, TrackableComponent
Direct Known Subclasses:
Mqtt3MessageDrivenChannelAdapter, Mqtt5MessageDrivenChannelAdapter

public abstract class AbstractMqttMessageDrivenChannelAdapter<T extends com.hivemq.client.mqtt.MqttClient> extends MessageProducerSupport implements ApplicationEventPublisherAware, ClientManager.ConnectCallback
Abstract class for MQTT Message-Driven Channel Adapters.
Since:
7.2
Author:
Jiandong Ma, WooSeung Kim
  • Field Details

  • Constructor Details

    • AbstractMqttMessageDrivenChannelAdapter

      protected AbstractMqttMessageDrivenChannelAdapter(ClientManager<T> mqttClientManager)
    • AbstractMqttMessageDrivenChannelAdapter

      protected AbstractMqttMessageDrivenChannelAdapter(ClientManager<T> mqttClientManager, String... topics)
  • Method Details

    • setApplicationEventPublisher

      public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface ApplicationEventPublisherAware
    • getApplicationEventPublisher

      protected ApplicationEventPublisher getApplicationEventPublisher()
    • onInit

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class MessageProducerSupport
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean
      Specified by:
      destroy in interface IntegrationManagement
      Overrides:
      destroy in class AbstractEndpoint
    • getClient

      protected T getClient()
    • setMessageConverter

      public void setMessageConverter(SmartMessageConverter messageConverter)
      Set the messageConverter to convert the payload to the expected payloadType.
      Parameters:
      messageConverter - the messageConverter
    • getMessageConverter

      protected SmartMessageConverter getMessageConverter()
    • getTopics

      protected String @Nullable [] getTopics()
    • setQos

      public void setQos(com.hivemq.client.mqtt.datatypes.MqttQos qos)
      Set the QoS for the topic
      Parameters:
      qos - The qos value
    • getQos

      protected com.hivemq.client.mqtt.datatypes.MqttQos getQos()
    • setManualAck

      public void setManualAck(boolean manualAck)
      Set whether the Publish messages are acknowledged manually.
      Parameters:
      manualAck - true for manual ack.
    • isManualAck

      protected boolean isManualAck()
    • setExecutor

      public void setExecutor(Executor executor)
      Set the executor where the message callback is executed on.
      Parameters:
      executor - the executor.
    • getExecutor

      protected @Nullable Executor getExecutor()
    • setPayloadType

      public void setPayloadType(Class<?> payloadType)
      Set the type of the target message payload to produce after conversion from MQTT message. Defaults to byte[].class. Can be set to Mqtt5Publish for v5 or Mqtt3Publish to produce the whole MQTT message as a payload.
      Parameters:
      payloadType - the expected payload type to convert MQTT message to.
    • getPayloadType

      protected Class<?> getPayloadType()
    • isConnected

      public boolean isConnected()
      Return whether the mqttClient isConnected.
      Returns:
      whether the mqttClient isConnected.
    • sendReceivedMessage

      protected void sendReceivedMessage(Object mqttPublish, Supplier<Message<?>> messageSupplier, SimpleAcknowledgment acknowledgment, Function<RuntimeException,MqttIntegrationEvent> conversionFailedEventFactory)
      Send a message built from a received MQTT publish. An exception must not be thrown into the MQTT client callback since it terminates the subscription. If the message cannot be built, the failure is logged, the publish is acknowledged in manual acknowledgment mode, and a conversion failure event is emitted. A downstream failure is sent to the error channel, if any; otherwise, or if the error flow fails, it is logged.
      Parameters:
      mqttPublish - the received MQTT publish.
      messageSupplier - the supplier for the message to send.
      acknowledgment - the acknowledgment for the received MQTT publish.
      conversionFailedEventFactory - the factory for the event to emit when the message cannot be built.
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageProducerSupport