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.eclipse.paho.client.mqttv3.IMqttAsyncClient,org.eclipse.paho.client.mqttv3.MqttConnectOptions>
org.springframework.integration.mqtt.outbound.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<org.eclipse.paho.client.mqttv3.IMqttAsyncClient,org.eclipse.paho.client.mqttv3.MqttConnectOptions>
implements org.eclipse.paho.client.mqttv3.MqttCallback, MqttPahoComponent
Eclipse Paho Implementation. When consuming
MqttIntegrationEvent
s
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, Artem Vozhdayenko, Christian Tzolov
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.mqtt.outbound.AbstractMqttMessageHandler
DEFAULT_COMPLETION_TIMEOUT, DISCONNECT_COMPLETION_TIMEOUT, lock
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
ConstructorDescriptionMqttPahoMessageHandler
(String url, String clientId) Use this constructor when you don't need additionalMqttConnectOptions
.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 theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
).MqttPahoMessageHandler
(String clientId, MqttPahoClientFactory clientFactory) Use this constructor if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
.MqttPahoMessageHandler
(ClientManager<org.eclipse.paho.client.mqttv3.IMqttAsyncClient, org.eclipse.paho.client.mqttv3.MqttConnectOptions> clientManager) Use this constructor when you need to use a singleClientManager
(for instance, to reuse an MQTT connection). -
Method Summary
Modifier and TypeMethodDescriptionvoid
connectionLost
(Throwable cause) void
deliveryComplete
(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token) protected void
doStart()
protected void
doStop()
org.eclipse.paho.client.mqttv3.MqttConnectOptions
Return information about the connection.void
messageArrived
(String topic, org.eclipse.paho.client.mqttv3.MqttMessage message) protected void
onInit()
Subclasses may implement this for initialization logic.protected void
void
setAsync
(boolean async) Set to true if you don't want to block when sending messages.void
setAsyncEvents
(boolean asyncEvents) WhensetAsync(boolean)
is true, setting this to true enables publication ofMqttMessageSentEvent
andMqttMessageDeliveredEvent
to be emitted.Methods inherited from class org.springframework.integration.mqtt.outbound.AbstractMqttMessageHandler
getApplicationEventPublisher, getClientId, getClientInstance, getClientManager, getCompletionTimeout, getComponentType, getConverter, getDefaultQos, getDefaultRetained, getDefaultTopic, getDisconnectCompletionTimeout, getQosProcessor, getRetainedProcessor, getTopicProcessor, getUrl, handleMessageInternal, incrementClientInstance, isRunning, setApplicationEventPublisher, setCompletionTimeout, setConverter, setDefaultQos, setDefaultRetained, setDefaultTopic, setDisconnectCompletionTimeout, setQosExpression, setQosExpressionString, setRetainedExpression, setRetainedExpressionString, setTopicExpression, setTopicExpressionString, start, stop
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, 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, 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
-
Constructor Details
-
MqttPahoMessageHandler
Use this constructor when you don't need additionalMqttConnectOptions
.- Parameters:
url
- The URL.clientId
- The client id.
-
MqttPahoMessageHandler
Use this constructor for a single url (although it may be overridden if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
).- Parameters:
url
- the URL.clientId
- The client id.clientFactory
- The client factory.
-
MqttPahoMessageHandler
Use this constructor if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
.- Parameters:
clientId
- The client id.clientFactory
- The client factory.- Since:
- 4.1
-
MqttPahoMessageHandler
public MqttPahoMessageHandler(ClientManager<org.eclipse.paho.client.mqttv3.IMqttAsyncClient, org.eclipse.paho.client.mqttv3.MqttConnectOptions> clientManager) Use this constructor when you need to use a singleClientManager
(for instance, to reuse an MQTT connection).- Parameters:
clientManager
- The client manager.- Since:
- 6.0
-
-
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) WhensetAsync(boolean)
is true, setting this to true enables publication ofMqttMessageSentEvent
andMqttMessageDeliveredEvent
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 interfaceMqttComponent<org.eclipse.paho.client.mqttv3.MqttConnectOptions>
- Specified by:
getConnectionInfo
in interfaceMqttPahoComponent
- Returns:
- the information.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractMqttMessageHandler<org.eclipse.paho.client.mqttv3.IMqttAsyncClient,
org.eclipse.paho.client.mqttv3.MqttConnectOptions>
-
doStart
protected void doStart()- Specified by:
doStart
in classAbstractMqttMessageHandler<org.eclipse.paho.client.mqttv3.IMqttAsyncClient,
org.eclipse.paho.client.mqttv3.MqttConnectOptions>
-
doStop
protected void doStop()- Specified by:
doStop
in classAbstractMqttMessageHandler<org.eclipse.paho.client.mqttv3.IMqttAsyncClient,
org.eclipse.paho.client.mqttv3.MqttConnectOptions>
-
publish
- Specified by:
publish
in classAbstractMqttMessageHandler<org.eclipse.paho.client.mqttv3.IMqttAsyncClient,
org.eclipse.paho.client.mqttv3.MqttConnectOptions>
-
connectionLost
- Specified by:
connectionLost
in interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
messageArrived
- Specified by:
messageArrived
in interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
deliveryComplete
public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token) - Specified by:
deliveryComplete
in interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-