Class MqttPahoMessageHandler

All Implemented Interfaces:
org.eclipse.paho.client.mqttv3.MqttCallback, org.reactivestreams.Subscriber<Message<?>>, Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, Ordered, ExpressionCapable, Orderable, IntegrationPattern, MqttComponent<org.eclipse.paho.client.mqttv3.MqttConnectOptions>, MqttPahoComponent, NamedComponent, IntegrationManagement, ManageableLifecycle, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class MqttPahoMessageHandler extends AbstractMqttMessageHandler implements org.eclipse.paho.client.mqttv3.MqttCallback, MqttPahoComponent
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
Author:
Gary Russell, Artem Bilan
  • Constructor Details

    • MqttPahoMessageHandler

      public MqttPahoMessageHandler(String url, 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(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(String url, 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
    • 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()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      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(String topic, Object mqttMessage, Message<?> message)
      Specified by:
      publish in class AbstractMqttMessageHandler
    • connectionLost

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

      public void messageArrived(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