Class MqttPahoMessageDrivenChannelAdapter

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.MqttPahoMessageDrivenChannelAdapter
All Implemented Interfaces:
org.eclipse.paho.client.mqttv3.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.client.mqttv3.MqttConnectOptions>, MqttPahoComponent, 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 MqttPahoMessageDrivenChannelAdapter
extends AbstractMqttMessageDrivenChannelAdapter
implements org.eclipse.paho.client.mqttv3.MqttCallback, MqttPahoComponent, org.springframework.context.ApplicationEventPublisherAware
Eclipse Paho Implementation. When consuming MqttIntegrationEvents published by this component use MqttPahoComponent adapter = event.getSourceAsType() to get a reference, allowing you to obtain the bean name and MqttConnectOptions. This technique allows consumption of events from both inbound and outbound endpoints in the same event listener.
Since:
4.0
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static long DEFAULT_COMPLETION_TIMEOUT
    The default completion timeout in milliseconds.
    static long DISCONNECT_COMPLETION_TIMEOUT
    The default disconnect completion timeout in milliseconds.

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

    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
    MqttPahoMessageDrivenChannelAdapter​(java.lang.String url, java.lang.String clientId, java.lang.String... topic)
    Use this constructor when you don't need additional MqttConnectOptions.
    MqttPahoMessageDrivenChannelAdapter​(java.lang.String url, java.lang.String clientId, MqttPahoClientFactory clientFactory, java.lang.String... topic)
    Use this constructor for a single url (although it may be overridden if the server URI(s) are provided by the MqttConnectOptions.getServerURIs() provided by the MqttPahoClientFactory).
    MqttPahoMessageDrivenChannelAdapter​(java.lang.String clientId, MqttPahoClientFactory clientFactory, java.lang.String... topic)
    Use this constructor if the server URI(s) are provided by the MqttConnectOptions.getServerURIs() provided by the MqttPahoClientFactory.
  • Method Summary

    Modifier and Type Method Description
    void addTopic​(java.lang.String topic, int qos)
    Add a topic to the subscribed list.
    void connectionLost​(java.lang.Throwable cause)  
    void deliveryComplete​(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)  
    protected void doStart()  
    protected void doStop()  
    org.eclipse.paho.client.mqttv3.MqttConnectOptions getConnectionInfo()
    Return information about the connection.
    void messageArrived​(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)  
    void removeTopic​(java.lang.String... topic)
    Remove a topic (or topics) from the subscribed list.
    void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)  
    void setCompletionTimeout​(long completionTimeout)
    Set the completion timeout for operations.
    void setDisconnectCompletionTimeout​(long completionTimeout)
    Set the completion timeout when disconnecting.
    void setManualAcks​(boolean manualAcks)
    Set the acknowledgment mode to manual.
    void setRecoveryInterval​(int recoveryInterval)
    The time (ms) to wait between reconnection attempts.

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

    addTopic, addTopics, getClientId, getComponentType, getConverter, getQos, getTopic, getUrl, onInit, setConverter, setQos

    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

    destroy, 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
  • Field Details

  • Constructor Details

    • MqttPahoMessageDrivenChannelAdapter

      public MqttPahoMessageDrivenChannelAdapter​(java.lang.String url, java.lang.String clientId, MqttPahoClientFactory clientFactory, java.lang.String... topic)
      Use this constructor for a single url (although it may be overridden if the server URI(s) are provided by the MqttConnectOptions.getServerURIs() provided by the MqttPahoClientFactory).
      Parameters:
      url - the URL.
      clientId - The client id.
      clientFactory - The client factory.
      topic - The topic(s).
    • MqttPahoMessageDrivenChannelAdapter

      public MqttPahoMessageDrivenChannelAdapter​(java.lang.String clientId, MqttPahoClientFactory clientFactory, java.lang.String... topic)
      Use this constructor if the server URI(s) are provided by the MqttConnectOptions.getServerURIs() provided by the MqttPahoClientFactory.
      Parameters:
      clientId - The client id.
      clientFactory - The client factory.
      topic - The topic(s).
      Since:
      4.1
    • MqttPahoMessageDrivenChannelAdapter

      public MqttPahoMessageDrivenChannelAdapter​(java.lang.String url, java.lang.String clientId, java.lang.String... topic)
      Use this constructor when you don't need additional MqttConnectOptions.
      Parameters:
      url - The URL.
      clientId - The client id.
      topic - The topic(s).
  • Method Details

    • setCompletionTimeout

      public void setCompletionTimeout​(long completionTimeout)
      Set the completion timeout for operations. Not settable using the namespace. Default 30000L milliseconds.
      Parameters:
      completionTimeout - The timeout.
      Since:
      4.1
    • setDisconnectCompletionTimeout

      public void setDisconnectCompletionTimeout​(long completionTimeout)
      Set the completion timeout when disconnecting. Not settable using the namespace. Default 5000L milliseconds.
      Parameters:
      completionTimeout - The timeout.
      Since:
      5.1.10
    • setRecoveryInterval

      public void setRecoveryInterval​(int recoveryInterval)
      The time (ms) to wait between reconnection attempts. Default 10000.
      Parameters:
      recoveryInterval - the interval.
      Since:
      4.2.2
    • setManualAcks

      public void setManualAcks​(boolean manualAcks)
      Set the acknowledgment mode to manual.
      Parameters:
      manualAcks - true for manual acks.
      Since:
      5.3
    • setApplicationEventPublisher

      public void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
      Since:
      4.2.2
    • getConnectionInfo

      public org.eclipse.paho.client.mqttv3.MqttConnectOptions getConnectionInfo()
      Description copied from interface: MqttComponent
      Return information about the connection.
      Specified by:
      getConnectionInfo in interface MqttComponent<org.eclipse.paho.client.mqttv3.MqttConnectOptions>
      Specified by:
      getConnectionInfo in interface MqttPahoComponent
      Returns:
      the information.
    • 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
    • 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.
    • connectionLost

      public void connectionLost​(java.lang.Throwable cause)
      Specified by:
      connectionLost in interface org.eclipse.paho.client.mqttv3.MqttCallback
    • messageArrived

      public void messageArrived​(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
      Specified by:
      messageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallback
    • deliveryComplete

      public void deliveryComplete​(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
      Specified by:
      deliveryComplete in interface org.eclipse.paho.client.mqttv3.MqttCallback