Class Mqttv5PahoMessageDrivenChannelAdapter

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
org.springframework.integration.mqtt.inbound.Mqttv5PahoMessageDrivenChannelAdapter
All Implemented Interfaces:
org.eclipse.paho.mqttv5.client.MqttCallback, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.core.MessageProducer, org.springframework.integration.IntegrationPattern, MqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent

public class Mqttv5PahoMessageDrivenChannelAdapter
extends AbstractMqttMessageDrivenChannelAdapter
implements org.eclipse.paho.mqttv5.client.MqttCallback, MqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
The AbstractMqttMessageDrivenChannelAdapter implementation for MQTT v5. The MqttProperties are mapped via the provided HeaderMapper; meanwhile the regular MqttMessage properties are always mapped into headers. It is recommended to have the MqttConnectionOptions.setAutomaticReconnect(boolean) set to true to let an internal IMqttAsyncClient instance to handle reconnects. Otherwise, only the manual restart of this component can handle reconnects, e.g. via MqttConnectionFailedEvent handling on disconnection. See setPayloadType(java.lang.Class<?>) for more information about type conversion.
Since:
5.5.5
  • Field Summary

    Fields inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter

    DEFAULT_COMPLETION_TIMEOUT, topicLock

    Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    lifecycleCondition, lifecycleLock

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors 
    Constructor Description
    Mqttv5PahoMessageDrivenChannelAdapter​(java.lang.String url, java.lang.String clientId, java.lang.String... topic)  
    Mqttv5PahoMessageDrivenChannelAdapter​(org.eclipse.paho.mqttv5.client.MqttConnectionOptions connectionOptions, java.lang.String clientId, java.lang.String... topic)  
  • Method Summary

    Modifier and Type Method Description
    void addTopic​(java.lang.String topic, int qos)
    Add a topic to the subscribed list.
    void authPacketArrived​(int reasonCode, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties)  
    void connectComplete​(boolean reconnect, java.lang.String serverURI)  
    void deliveryComplete​(org.eclipse.paho.mqttv5.client.IMqttToken token)  
    void destroy()  
    void disconnected​(org.eclipse.paho.mqttv5.client.MqttDisconnectResponse disconnectResponse)  
    protected void doStart()  
    protected void doStop()  
    org.eclipse.paho.mqttv5.client.MqttConnectionOptions getConnectionInfo()
    Return information about the connection.
    void messageArrived​(java.lang.String topic, org.eclipse.paho.mqttv5.common.MqttMessage mqttMessage)  
    void mqttErrorOccurred​(org.eclipse.paho.mqttv5.common.MqttException exception)  
    protected void onInit()  
    void removeTopic​(java.lang.String... topic)
    Remove a topic (or topics) from the subscribed list.
    void setConverter​(MqttMessageConverter converter)  
    void setHeaderMapper​(org.springframework.integration.mapping.HeaderMapper<org.eclipse.paho.mqttv5.common.packet.MqttProperties> headerMapper)  
    void setMessageConverter​(org.springframework.messaging.converter.SmartMessageConverter messageConverter)  
    void setPayloadType​(java.lang.Class<?> payloadType)
    Set the type of the target message payload to produce after conversion from MQTT message.
    void setPersistence​(org.eclipse.paho.mqttv5.client.MqttClientPersistence persistence)  

    Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport

    afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisher

    Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.springframework.beans.factory.BeanNameAware

    setBeanName

    Methods inherited from interface org.springframework.integration.mqtt.core.MqttComponent

    getBeanName

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Constructor Details

    • Mqttv5PahoMessageDrivenChannelAdapter

      public Mqttv5PahoMessageDrivenChannelAdapter​(java.lang.String url, java.lang.String clientId, java.lang.String... topic)
    • Mqttv5PahoMessageDrivenChannelAdapter

      public Mqttv5PahoMessageDrivenChannelAdapter​(org.eclipse.paho.mqttv5.client.MqttConnectionOptions connectionOptions, java.lang.String clientId, java.lang.String... topic)
  • Method Details

    • getConnectionInfo

      public org.eclipse.paho.mqttv5.client.MqttConnectionOptions getConnectionInfo()
      Description copied from interface: MqttComponent
      Return information about the connection.
      Specified by:
      getConnectionInfo in interface MqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
      Returns:
      the information.
    • setPersistence

      public void setPersistence​(@Nullable org.eclipse.paho.mqttv5.client.MqttClientPersistence persistence)
    • setConverter

      public void setConverter​(MqttMessageConverter converter)
      Overrides:
      setConverter in class AbstractMqttMessageDrivenChannelAdapter
    • setMessageConverter

      public void setMessageConverter​(org.springframework.messaging.converter.SmartMessageConverter messageConverter)
    • setPayloadType

      public void setPayloadType​(java.lang.Class<?> payloadType)
      Set the type of the target message payload to produce after conversion from MQTT message. Defaults to byte[].class - just extract MQTT message payload without conversion. Can be set to MqttMessage class to produce the whole MQTT message as a payload.
      Parameters:
      payloadType - the expected payload type to convert MQTT message to.
    • setHeaderMapper

      public void setHeaderMapper​(org.springframework.integration.mapping.HeaderMapper<org.eclipse.paho.mqttv5.common.packet.MqttProperties> headerMapper)
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.endpoint.MessageProducerSupport
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.springframework.integration.endpoint.MessageProducerSupport
    • doStop

      protected void doStop()
      Overrides:
      doStop in class org.springframework.integration.endpoint.MessageProducerSupport
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Overrides:
      destroy in class org.springframework.integration.endpoint.AbstractEndpoint
    • addTopic

      public void addTopic​(java.lang.String topic, int qos)
      Description copied from class: AbstractMqttMessageDrivenChannelAdapter
      Add a topic to the subscribed list.
      Overrides:
      addTopic in class AbstractMqttMessageDrivenChannelAdapter
      Parameters:
      topic - The topic.
      qos - The qos.
    • removeTopic

      public void removeTopic​(java.lang.String... topic)
      Description copied from class: AbstractMqttMessageDrivenChannelAdapter
      Remove a topic (or topics) from the subscribed list.
      Overrides:
      removeTopic in class AbstractMqttMessageDrivenChannelAdapter
      Parameters:
      topic - The topic.
    • messageArrived

      public void messageArrived​(java.lang.String topic, org.eclipse.paho.mqttv5.common.MqttMessage mqttMessage)
      Specified by:
      messageArrived in interface org.eclipse.paho.mqttv5.client.MqttCallback
    • 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
    • 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, java.lang.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