Class AbstractMqttMessageHandler

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.mqtt.outbound.AbstractMqttMessageHandler
All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>, 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.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.core.Ordered, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.Orderable, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.TrackableComponent, org.springframework.messaging.MessageHandler, reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>
Direct Known Subclasses:
MqttPahoMessageHandler, Mqttv5PahoMessageHandler

public abstract class AbstractMqttMessageHandler
extends org.springframework.integration.handler.AbstractMessageHandler
implements org.springframework.integration.support.management.ManageableLifecycle, org.springframework.context.ApplicationEventPublisherAware
Abstract class for MQTT outbound channel adapters.
Since:
4.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • 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.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractMqttMessageHandler​(java.lang.String url, java.lang.String clientId)  
  • Method Summary

    Modifier and Type Method Description
    protected abstract void doStart()  
    protected abstract void doStop()  
    protected org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()  
    java.lang.String getClientId()  
    int getClientInstance()
    Incremented each time the client is connected.
    protected long getCompletionTimeout()  
    java.lang.String getComponentType()  
    protected org.springframework.messaging.converter.MessageConverter getConverter()  
    protected int getDefaultQos()  
    protected boolean getDefaultRetained()  
    protected java.lang.String getDefaultTopic()  
    protected long getDisconnectCompletionTimeout()  
    protected org.springframework.integration.handler.MessageProcessor<java.lang.Integer> getQosProcessor()  
    protected org.springframework.integration.handler.MessageProcessor<java.lang.Boolean> getRetainedProcessor()  
    protected org.springframework.integration.handler.MessageProcessor<java.lang.String> getTopicProcessor()  
    protected java.lang.String getUrl()  
    protected void handleMessageInternal​(org.springframework.messaging.Message<?> message)  
    protected void incrementClientInstance()  
    boolean isRunning()  
    protected void onInit()  
    protected abstract void publish​(java.lang.String topic, java.lang.Object mqttMessage, org.springframework.messaging.Message<?> message)  
    void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)  
    void setCompletionTimeout​(long completionTimeout)
    Set the completion timeout for async operations.
    void setConverter​(org.springframework.messaging.converter.MessageConverter converter)
    Set the message converter to use; if this is provided, the adapter qos and retained settings are ignored.
    void setDefaultQos​(int defaultQos)
    Set the qos for messages if the qosExpression evaluates to null.
    void setDefaultRetained​(boolean defaultRetained)
    Set the retained boolean for messages if the retainedExpression evaluates to null.
    void setDefaultTopic​(java.lang.String defaultTopic)
    Set the topic to which the message will be published if the topicExpression evaluates to `null`.
    void setDisconnectCompletionTimeout​(long completionTimeout)
    Set the completion timeout when disconnecting.
    void setQosExpression​(org.springframework.expression.Expression qosExpression)
    Set the qos expression; default "headers['mqtt_qos']".
    void setQosExpressionString​(java.lang.String qosExpression)
    Set the qos expression; default "headers['mqtt_qos']".
    void setRetainedExpression​(org.springframework.expression.Expression retainedExpression)
    Set the retained expression; default "headers['mqtt_retained']".
    void setRetainedExpressionString​(java.lang.String retainedExpression)
    Set the retained expression; default "headers['mqtt_retained']".
    void setTopicExpression​(org.springframework.expression.Expression topicExpression)
    Set the topic expression; default "headers['mqtt_topic']".
    void setTopicExpressionString​(java.lang.String topicExpression)
    Set the topic expression; default "headers['mqtt_topic']".
    void start()  
    void stop()  

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack

    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 reactor.core.CoreSubscriber

    currentContext

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

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

    getBeanName, getComponentName
  • Field Details

  • Constructor Details

  • Method Details

    • setApplicationEventPublisher

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

      protected org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
    • setDefaultTopic

      public void setDefaultTopic​(java.lang.String defaultTopic)
      Set the topic to which the message will be published if the topicExpression evaluates to `null`.
      Parameters:
      defaultTopic - the default topic.
    • getDefaultTopic

      protected java.lang.String getDefaultTopic()
    • setTopicExpression

      public void setTopicExpression​(org.springframework.expression.Expression topicExpression)
      Set the topic expression; default "headers['mqtt_topic']".
      Parameters:
      topicExpression - the expression.
      Since:
      5.0
    • setTopicExpressionString

      public void setTopicExpressionString​(java.lang.String topicExpression)
      Set the topic expression; default "headers['mqtt_topic']".
      Parameters:
      topicExpression - the expression.
      Since:
      5.0
    • getTopicProcessor

      protected org.springframework.integration.handler.MessageProcessor<java.lang.String> getTopicProcessor()
    • setDefaultQos

      public void setDefaultQos​(int defaultQos)
      Set the qos for messages if the qosExpression evaluates to null. Only applies if a message converter is not provided.
      Parameters:
      defaultQos - the default qos.
      See Also:
      setConverter(MessageConverter)
    • getDefaultQos

      protected int getDefaultQos()
    • setQosExpression

      public void setQosExpression​(org.springframework.expression.Expression qosExpression)
      Set the qos expression; default "headers['mqtt_qos']". Only applies if a message converter is not provided.
      Parameters:
      qosExpression - the expression.
      Since:
      5.0
      See Also:
      setConverter(MessageConverter)
    • setQosExpressionString

      public void setQosExpressionString​(java.lang.String qosExpression)
      Set the qos expression; default "headers['mqtt_qos']". Only applies if a message converter is not provided.
      Parameters:
      qosExpression - the expression.
      Since:
      5.0
      See Also:
      setConverter(MessageConverter)
    • getQosProcessor

      protected org.springframework.integration.handler.MessageProcessor<java.lang.Integer> getQosProcessor()
    • setDefaultRetained

      public void setDefaultRetained​(boolean defaultRetained)
      Set the retained boolean for messages if the retainedExpression evaluates to null. Only applies if a message converter is not provided.
      Parameters:
      defaultRetained - the default defaultRetained.
      See Also:
      setConverter(MessageConverter)
    • getDefaultRetained

      protected boolean getDefaultRetained()
    • setRetainedExpression

      public void setRetainedExpression​(org.springframework.expression.Expression retainedExpression)
      Set the retained expression; default "headers['mqtt_retained']". Only applies if a message converter is not provided.
      Parameters:
      retainedExpression - the expression.
      Since:
      5.0
      See Also:
      setConverter(MessageConverter)
    • setRetainedExpressionString

      public void setRetainedExpressionString​(java.lang.String retainedExpression)
      Set the retained expression; default "headers['mqtt_retained']". Only applies if a message converter is not provided.
      Parameters:
      retainedExpression - the expression.
      Since:
      5.0
      See Also:
      setConverter(MessageConverter)
    • getRetainedProcessor

      protected org.springframework.integration.handler.MessageProcessor<java.lang.Boolean> getRetainedProcessor()
    • setConverter

      public void setConverter​(org.springframework.messaging.converter.MessageConverter converter)
      Set the message converter to use; if this is provided, the adapter qos and retained settings are ignored.
      Parameters:
      converter - the converter.
    • getConverter

      protected org.springframework.messaging.converter.MessageConverter getConverter()
    • getUrl

      @Nullable protected java.lang.String getUrl()
    • getClientId

      public java.lang.String getClientId()
    • getClientInstance

      public int getClientInstance()
      Incremented each time the client is connected.
      Returns:
      The instance;
      Since:
      4.1
    • getComponentType

      public java.lang.String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.handler.MessageHandlerSupport
    • incrementClientInstance

      protected void incrementClientInstance()
    • setCompletionTimeout

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

      protected long getCompletionTimeout()
    • 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
    • getDisconnectCompletionTimeout

      protected long getDisconnectCompletionTimeout()
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.context.IntegrationObjectSupport
    • start

      public final void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Specified by:
      start in interface org.springframework.integration.support.management.ManageableLifecycle
    • doStart

      protected abstract void doStart()
    • stop

      public final void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface org.springframework.integration.support.management.ManageableLifecycle
    • doStop

      protected abstract void doStop()
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Specified by:
      isRunning in interface org.springframework.integration.support.management.ManageableLifecycle
    • handleMessageInternal

      protected void handleMessageInternal​(org.springframework.messaging.Message<?> message)
      Specified by:
      handleMessageInternal in class org.springframework.integration.handler.AbstractMessageHandler
    • publish

      protected abstract void publish​(java.lang.String topic, java.lang.Object mqttMessage, org.springframework.messaging.Message<?> message)