Class MqttPahoMessageHandler

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.mqtt.outbound.AbstractMqttMessageHandler
org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler
All Implemented Interfaces:
org.eclipse.paho.client.mqttv3.MqttCallback, 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, MqttComponent<org.eclipse.paho.client.mqttv3.MqttConnectOptions>, MqttPahoComponent, 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<?>>

public class MqttPahoMessageHandler
extends AbstractMqttMessageHandler
implements org.eclipse.paho.client.mqttv3.MqttCallback, MqttPahoComponent, org.springframework.context.ApplicationEventPublisherAware
Eclipse Paho Implementation. When consuming MqttIntegrationEvents published by this component use MqttPahoComponent handler = 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
  • 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
    MqttPahoMessageHandler​(java.lang.String url, java.lang.String clientId)
    Use this constructor when you don't need additional MqttConnectOptions.
    MqttPahoMessageHandler​(java.lang.String url, java.lang.String clientId, MqttPahoClientFactory clientFactory)
    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).
    MqttPahoMessageHandler​(java.lang.String clientId, MqttPahoClientFactory clientFactory)
    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 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 message)  
    protected void onInit()  
    protected void publish​(java.lang.String topic, java.lang.Object mqttMessage, org.springframework.messaging.Message<?> message)  
    void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)  
    void setAsync​(boolean async)
    Set to true if you don't want to block when sending messages.
    void setAsyncEvents​(boolean asyncEvents)
    When setAsync(boolean) is true, setting this to true enables publication of MqttMessageSentEvent and MqttMessageDeliveredEvent to be emitted.
    void setCompletionTimeout​(long completionTimeout)
    Set the completion timeout for async operations.
    void setDisconnectCompletionTimeout​(long completionTimeout)
    Set the completion timeout when disconnecting.

    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 org.springframework.beans.factory.BeanNameAware

    setBeanName

    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.mqtt.core.MqttComponent

    getBeanName

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

    getBeanName, getComponentName
  • Field Details

  • Constructor Details

    • MqttPahoMessageHandler

      public MqttPahoMessageHandler​(java.lang.String url, java.lang.String clientId, MqttPahoClientFactory clientFactory)
      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.
    • MqttPahoMessageHandler

      public MqttPahoMessageHandler​(java.lang.String clientId, MqttPahoClientFactory clientFactory)
      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.
      Since:
      4.1
    • MqttPahoMessageHandler

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

    • setAsync

      public void setAsync​(boolean async)
      Set to true if you don't want to block when sending messages. Default false. When true, message sent/delivered events will be published for reception by a suitably configured 'ApplicationListener' or an event inbound-channel-adapter.
      Parameters:
      async - true for async.
      Since:
      4.1
    • setAsyncEvents

      public void setAsyncEvents​(boolean asyncEvents)
      When setAsync(boolean) is true, setting this to true enables publication of MqttMessageSentEvent and MqttMessageDeliveredEvent to be emitted. Default false.
      Parameters:
      asyncEvents - the asyncEvents.
      Since:
      4.1
    • 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
    • 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
    • setApplicationEventPublisher

      public void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • 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.
    • onInit

      protected void onInit()
      Overrides:
      onInit in class AbstractMqttMessageHandler
    • doStart

      protected void doStart()
      Specified by:
      doStart in class AbstractMqttMessageHandler
    • doStop

      protected void doStop()
      Specified by:
      doStop in class AbstractMqttMessageHandler
    • publish

      protected void publish​(java.lang.String topic, java.lang.Object mqttMessage, org.springframework.messaging.Message<?> message)
      Specified by:
      publish in class AbstractMqttMessageHandler
    • 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 message)
      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